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

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

h = A("h")
a = B("a")
b = A("b")
l = B("l")
c = B("c")

h.t = l
a.x = c
b.t = l
l.x = a
c.x = a
assert a.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

h = A("h")
a = B("a")
b = A("b")
l = B("l")
c = B("c")

h.t = l
a.x = c
b.t = l
l.x = a
c.x = a
assert a.x.x.x.x.txt == "a"