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

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

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

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

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

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

a.q = n
m.u = a
n.u = a
assert n.u.q.u.txt == "a"