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

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

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

j.r = l
l.z = j
a.r = l
assert l.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

j.r = l
l.z = j
a.r = l
assert l.z.r.z.txt == "j"