class A:
    def __init__(self, txt: str):
        self.q: 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")
j = B("j")

m.q = j
c.t = m
j.t = m
assert c.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: 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")
j = B("j")

m.q = j
c.t = m
j.t = m
assert c.t.q.t.txt == "m"