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

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

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

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

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

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

a.t = d
i.t = a
i.s = a
d.t = a
d.s = a
h.t = a
h.s = a
assert i.t.t.s.txt == "a"