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

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

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

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

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

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

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