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

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

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

h = A("h")
e = B("e")
m = C("m")
d = B("d")

h.t = d
h.s = e
e.p = d
e.s = h
m.z = h
m.p = h
d.p = e
d.s = h
assert e.p.s.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.s: B = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
m = C("m")
d = B("d")

h.t = d
h.s = e
e.p = d
e.s = h
m.z = h
m.p = h
d.p = e
d.s = h
assert e.p.s.s.p.txt == "d"