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

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

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

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

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

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

j.u = l
j.q = l
m.r = l
m.v = l
b.r = j
b.v = j
l.u = j
l.q = j
assert l.u.u.q.txt == "j"