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

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

e = A("e")
d = B("d")
h = B("h")
m = B("m")
g = B("g")
i = A("i")
k = B("k")

e.p = i
e.z = i
d.s = e
h.s = e
m.s = e
g.s = i
i.p = e
i.z = e
k.s = i
assert m.s.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
h = B("h")
m = B("m")
g = B("g")
i = A("i")
k = B("k")

e.p = i
e.z = i
d.s = e
h.s = e
m.s = e
g.s = i
i.p = e
i.z = e
k.s = i
assert m.s.p.p.p.txt == "i"