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

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

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

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

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

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

n.z = c
l.p = h
l.q = e
d.p = k
d.q = e
i.z = h
h.z = i
e.p = h
e.q = l
k.z = c
m.z = n
c.z = k
assert m.z.z.z.z.z.z.z.z.z.txt == "k"