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.u: A = None
        self.txt = txt

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

m.p = f
m.z = f
a.u = k
i.p = h
i.z = f
c.u = k
k.p = n
k.z = f
e.u = h
f.p = i
f.z = h
h.p = m
h.z = i
n.p = m
n.z = f
d.u = k
assert m.z.p.z.z.z.z.p.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.u: A = None
        self.txt = txt

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

m.p = f
m.z = f
a.u = k
i.p = h
i.z = f
c.u = k
k.p = n
k.z = f
e.u = h
f.p = i
f.z = h
h.p = m
h.z = i
n.p = m
n.z = f
d.u = k
assert m.z.p.z.z.z.z.p.p.p.p.txt == "f"