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

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

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

l = A("l")
j = B("j")
d = C("d")
f = A("f")
b = A("b")
a = B("a")
n = C("n")
m = A("m")

l.z = j
l.q = d
j.x = a
d.x = a
d.q = n
d.z = m
f.z = a
f.q = d
b.z = a
b.q = n
a.x = j
n.x = j
n.q = d
n.z = b
m.z = j
m.q = d
assert m.q.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: C = None
        self.txt = txt

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

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

l = A("l")
j = B("j")
d = C("d")
f = A("f")
b = A("b")
a = B("a")
n = C("n")
m = A("m")

l.z = j
l.q = d
j.x = a
d.x = a
d.q = n
d.z = m
f.z = a
f.q = d
b.z = a
b.q = n
a.x = j
n.x = j
n.q = d
n.z = b
m.z = j
m.q = d
assert m.q.x.x.x.x.txt == "j"