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

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

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

m = A("m")
c = B("c")
g = C("g")
e = C("e")
f = B("f")

m.t = g
c.w = m
c.o = m
c.p = e
g.p = m
e.p = m
f.w = m
f.o = m
f.p = e
assert m.t.p.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

m = A("m")
c = B("c")
g = C("g")
e = C("e")
f = B("f")

m.t = g
c.w = m
c.o = m
c.p = e
g.p = m
e.p = m
f.w = m
f.o = m
f.p = e
assert m.t.p.t.p.t.txt == "g"