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

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

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

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

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

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

a.t = f
f.r = m
f.o = a
m.r = f
m.o = a
assert m.o.t.r.txt == "m"