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

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

a = A("a")
n = B("n")
h = B("h")
k = B("k")
l = A("l")
j = B("j")
g = A("g")
e = B("e")

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

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

a = A("a")
n = B("n")
h = B("h")
k = B("k")
l = A("l")
j = B("j")
g = A("g")
e = B("e")

a.z = k
n.p = h
n.s = h
h.p = n
h.s = n
k.p = j
k.s = e
l.z = k
j.p = e
j.s = h
g.z = k
e.p = h
e.s = h
assert k.p.s.p.p.txt == "h"