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

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

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

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

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

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

m.r = f
f.q = m
b.q = m
assert f.q.r.q.txt == "m"