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

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

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

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

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

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

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