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

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

k = A("k")
l = B("l")
d = B("d")
a = B("a")
e = A("e")
n = B("n")
m = B("m")

k.s = e
k.p = d
l.z = e
d.z = e
a.z = k
e.s = k
e.p = l
n.z = k
m.z = k
assert n.z.p.z.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: B = None
        self.txt = txt

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

k = A("k")
l = B("l")
d = B("d")
a = B("a")
e = A("e")
n = B("n")
m = B("m")

k.s = e
k.p = d
l.z = e
d.z = e
a.z = k
e.s = k
e.p = l
n.z = k
m.z = k
assert n.z.p.z.s.s.txt == "e"