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

class B:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: A = None
        self.t: A = None
        self.txt = txt

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

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

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

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

class B:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: A = None
        self.t: A = None
        self.txt = txt

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

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

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

a.z = j
f.x = d
f.z = a
f.t = a
e.z = f
e.q = b
e.p = b
b.z = a
b.t = m
b.s = m
b.r = n
j.z = d
j.q = b
j.p = b
n.x = f
n.z = a
n.t = a
m.z = f
m.q = b
m.p = b
d.x = n
d.z = a
d.t = a
c.z = n
c.q = b
c.p = b
assert m.q.s.z.t.z.z.z.z.p.txt == "b"