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

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

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

f = A("f")
a = B("a")
d = C("d")
i = C("i")
l = C("l")
c = B("c")
e = A("e")
g = C("g")
j = B("j")
m = B("m")

f.q = i
a.z = g
d.q = i
d.z = j
d.r = l
i.q = l
i.r = l
i.z = m
l.q = d
l.z = j
l.r = i
c.z = d
e.q = i
g.q = l
g.r = l
g.z = a
j.z = d
m.z = d
assert a.z.q.r.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
d = C("d")
i = C("i")
l = C("l")
c = B("c")
e = A("e")
g = C("g")
j = B("j")
m = B("m")

f.q = i
a.z = g
d.q = i
d.z = j
d.r = l
i.q = l
i.r = l
i.z = m
l.q = d
l.z = j
l.r = i
c.z = d
e.q = i
g.q = l
g.r = l
g.z = a
j.z = d
m.z = d
assert a.z.q.r.z.z.z.z.z.z.txt == "d"