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

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

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

i.z = a
l.p = i
l.z = a
a.z = i
assert i.z.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.p: A = None
        self.z: A = None
        self.txt = txt

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

i.z = a
l.p = i
l.z = a
a.z = i
assert i.z.z.z.txt == "a"