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

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

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

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

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

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

m.q = e
a.r = f
f.q = e
e.r = m
assert e.r.q.r.txt == "m"