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

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

b = A("b")
m = B("m")
d = A("d")

b.t = d
m.u = d
d.t = b
assert m.u.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: A = None
        self.txt = txt

b = A("b")
m = B("m")
d = A("d")

b.t = d
m.u = d
d.t = b
assert m.u.t.t.txt == "d"