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

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

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

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

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

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

j.u = m
d.q = j
m.u = j
b.u = m
assert m.u.u.u.txt == "j"