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

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

a = A("a")
m = B("m")
c = A("c")

a.t = m
a.u = c
m.r = a
c.t = m
c.u = a
assert m.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.u: A = None
        self.txt = txt

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

a = A("a")
m = B("m")
c = A("c")

a.t = m
a.u = c
m.r = a
c.t = m
c.u = a
assert m.r.t.r.txt == "a"