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

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

class C:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: D = None
        self.p: B = None
        self.t: D = None
        self.txt = txt

m = A("m")
b = B("b")
f = C("f")
g = D("g")
j = B("j")
e = D("e")
d = C("d")
n = C("n")

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

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

class C:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: D = None
        self.p: B = None
        self.t: D = None
        self.txt = txt

m = A("m")
b = B("b")
f = C("f")
g = D("g")
j = B("j")
e = D("e")
d = C("d")
n = C("n")

m.z = g
b.p = e
b.q = f
b.t = f
b.x = m
f.t = g
g.q = j
g.p = j
g.v = e
g.t = e
j.p = e
j.q = n
j.t = n
j.x = m
e.q = j
e.v = g
e.t = g
e.p = b
d.t = e
n.t = e
assert f.t.v.v.q.t.t.t.p.txt == "j"