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

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

l = A("l")
k = B("k")
i = B("i")
g = A("g")

l.z = i
l.p = g
k.z = i
k.s = i
i.z = k
i.s = k
g.z = k
g.p = l
assert l.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: A = None
        self.txt = txt

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

l = A("l")
k = B("k")
i = B("i")
g = A("g")

l.z = i
l.p = g
k.z = i
k.s = i
i.z = k
i.s = k
g.z = k
g.p = l
assert l.z.z.z.txt == "i"