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

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

d = A("d")
f = B("f")
h = A("h")
a = A("a")
b = B("b")

d.t = h
f.u = b
h.t = d
a.t = h
b.u = f
assert d.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

d = A("d")
f = B("f")
h = A("h")
a = A("a")
b = B("b")

d.t = h
f.u = b
h.t = d
a.t = h
b.u = f
assert d.t.t.t.t.txt == "d"