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

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

m = A("m")
a = B("a")
d = B("d")
h = A("h")

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

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

m = A("m")
a = B("a")
d = B("d")
h = A("h")

m.t = a
a.p = d
d.p = a
h.t = a
assert m.t.p.p.p.txt == "d"