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

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

a = A("a")
b = B("b")
n = B("n")

a.q = n
b.v = a
n.v = a
assert a.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

a = A("a")
b = B("b")
n = B("n")

a.q = n
b.v = a
n.v = a
assert a.q.v.q.txt == "n"