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

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

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

j.r = l
g.r = l
l.r = j
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.r: A = None
        self.txt = txt

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

j.r = l
g.r = l
l.r = j
assert l.r.r.r.txt == "j"