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

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

n = A("n")
g = B("g")
h = A("h")
m = A("m")
j = A("j")
d = B("d")
a = A("a")
e = A("e")
l = B("l")
c = B("c")

n.w = e
n.p = c
g.w = e
h.w = e
h.p = l
m.w = h
m.p = l
j.w = h
j.p = d
d.w = h
a.w = h
a.p = l
e.w = n
e.p = d
l.w = h
c.w = a
assert a.w.w.p.w.w.p.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: B = None
        self.txt = txt

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

n = A("n")
g = B("g")
h = A("h")
m = A("m")
j = A("j")
d = B("d")
a = A("a")
e = A("e")
l = B("l")
c = B("c")

n.w = e
n.p = c
g.w = e
h.w = e
h.p = l
m.w = h
m.p = l
j.w = h
j.p = d
d.w = h
a.w = h
a.p = l
e.w = n
e.p = d
l.w = h
c.w = a
assert a.w.w.p.w.w.p.w.w.txt == "e"