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

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

k = A("k")
f = B("f")
h = B("h")
i = A("i")
e = B("e")
a = A("a")
c = A("c")
m = B("m")

k.w = f
f.p = c
f.z = i
h.p = a
h.z = k
i.w = h
e.p = c
e.z = k
a.w = e
c.w = e
m.p = a
m.z = k
assert i.w.z.w.z.w.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

k = A("k")
f = B("f")
h = B("h")
i = A("i")
e = B("e")
a = A("a")
c = A("c")
m = B("m")

k.w = f
f.p = c
f.z = i
h.p = a
h.z = k
i.w = h
e.p = c
e.z = k
a.w = e
c.w = e
m.p = a
m.z = k
assert i.w.z.w.z.w.p.w.p.txt == "c"