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

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

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

n.r = m
n.p = k
i.u = a
m.r = h
m.p = l
a.u = i
e.u = a
k.u = i
l.u = k
h.r = j
h.p = k
d.u = e
j.r = n
j.p = l
assert n.p.u.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: B = None
        self.txt = txt

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

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

n.r = m
n.p = k
i.u = a
m.r = h
m.p = l
a.u = i
e.u = a
k.u = i
l.u = k
h.r = j
h.p = k
d.u = e
j.r = n
j.p = l
assert n.p.u.u.u.u.u.u.u.u.txt == "a"