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

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

l = A("l")
b = B("b")
m = A("m")

l.q = m
b.u = l
m.q = l
assert l.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
m = A("m")

l.q = m
b.u = l
m.q = l
assert l.q.q.q.txt == "m"