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

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

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

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

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

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

b.q = a
c.r = m
m.r = c
a.q = b
assert c.r.r.r.txt == "m"