class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: A = None
        self.z: B = None
        self.r: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.s: D = None
        self.v: D = None
        self.txt = txt

n = A("n")
l = B("l")
m = C("m")
b = D("b")
j = D("j")
c = D("c")
a = B("a")
f = D("f")
g = B("g")

n.r = c
l.x = m
l.p = a
m.t = a
m.q = n
m.z = l
m.r = j
b.s = f
b.v = j
j.s = c
j.v = f
c.s = f
c.v = j
a.x = m
a.p = l
f.s = b
f.v = j
g.x = m
g.p = l
assert c.s.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: A = None
        self.z: B = None
        self.r: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.s: D = None
        self.v: D = None
        self.txt = txt

n = A("n")
l = B("l")
m = C("m")
b = D("b")
j = D("j")
c = D("c")
a = B("a")
f = D("f")
g = B("g")

n.r = c
l.x = m
l.p = a
m.t = a
m.q = n
m.z = l
m.r = j
b.s = f
b.v = j
j.s = c
j.v = f
c.s = f
c.v = j
a.x = m
a.p = l
f.s = b
f.v = j
g.x = m
g.p = l
assert c.s.v.v.v.txt == "j"