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

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

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

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

b.s = c
b.p = h
h.t = c
e.z = c
e.o = a
i.s = e
i.p = a
a.t = c
c.z = e
c.o = h
m.s = e
m.p = a
assert m.s.o.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.p: B = None
        self.txt = txt

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

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

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

b.s = c
b.p = h
h.t = c
e.z = c
e.o = a
i.s = e
i.p = a
a.t = c
c.z = e
c.o = h
m.s = e
m.p = a
assert m.s.o.t.o.t.txt == "c"