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

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

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

i = A("i")
g = B("g")
b = C("b")
d = B("d")
m = B("m")
k = C("k")

i.o = k
g.p = b
b.z = g
b.y = d
d.p = k
m.p = b
k.z = g
k.y = g
assert d.p.y.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

i = A("i")
g = B("g")
b = C("b")
d = B("d")
m = B("m")
k = C("k")

i.o = k
g.p = b
b.z = g
b.y = d
d.p = k
m.p = b
k.z = g
k.y = g
assert d.p.y.p.z.txt == "g"