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

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

h = A("h")
c = B("c")
m = A("m")
j = B("j")
l = B("l")
k = A("k")
g = B("g")
n = A("n")

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

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

h = A("h")
c = B("c")
m = A("m")
j = B("j")
l = B("l")
k = A("k")
g = B("g")
n = A("n")

h.p = g
h.z = k
c.x = m
c.s = j
m.p = l
m.z = k
j.x = n
j.s = l
l.x = m
l.s = j
k.p = l
k.z = h
g.x = k
g.s = c
n.p = l
n.z = m
assert k.z.z.z.p.x.p.x.z.txt == "k"