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

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

d = A("d")
c = B("c")
h = A("h")
e = B("e")
n = B("n")
a = B("a")
j = A("j")
k = B("k")
b = A("b")
f = B("f")

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

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

d = A("d")
c = B("c")
h = A("h")
e = B("e")
n = B("n")
a = B("a")
j = A("j")
k = B("k")
b = A("b")
f = B("f")

d.p = e
c.w = n
h.p = c
e.w = f
n.w = k
a.w = e
j.p = k
k.w = c
b.p = e
f.w = c
assert n.w.w.w.w.w.w.txt == "n"