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

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

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

l = A("l")
a = B("a")
g = C("g")
c = C("c")
b = B("b")
e = B("e")
d = A("d")

l.q = d
a.u = d
g.p = e
g.z = l
g.t = a
c.p = b
c.z = d
c.t = a
b.u = l
e.u = d
d.q = l
assert d.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

l = A("l")
a = B("a")
g = C("g")
c = C("c")
b = B("b")
e = B("e")
d = A("d")

l.q = d
a.u = d
g.p = e
g.z = l
g.t = a
c.p = b
c.z = d
c.t = a
b.u = l
e.u = d
d.q = l
assert d.q.q.q.q.txt == "d"