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

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

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

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

i.z = e
g.z = e
g.p = e
d.q = e
d.x = m
e.z = g
e.p = g
m.q = g
m.x = d
assert e.p.p.p.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

i.z = e
g.z = e
g.p = e
d.q = e
d.x = m
e.z = g
e.p = g
m.q = g
m.x = d
assert e.p.p.p.z.z.txt == "g"