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

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

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

b = A("b")
c = B("c")
h = C("h")
m = C("m")
g = B("g")
d = C("d")
e = A("e")
i = C("i")

b.q = d
b.p = e
c.q = g
h.u = b
m.u = e
g.q = c
d.u = b
e.q = d
e.p = b
i.u = e
assert g.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: A = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
h = C("h")
m = C("m")
g = B("g")
d = C("d")
e = A("e")
i = C("i")

b.q = d
b.p = e
c.q = g
h.u = b
m.u = e
g.q = c
d.u = b
e.q = d
e.p = b
i.u = e
assert g.q.q.q.q.q.q.q.txt == "c"