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

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

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

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

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

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

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