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

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

a = A("a")
n = B("n")
m = A("m")
h = A("h")
c = A("c")
j = B("j")
b = B("b")
i = B("i")
e = B("e")

a.w = m
n.x = m
n.p = j
m.w = h
h.w = c
c.w = m
j.x = m
j.p = e
b.x = c
b.p = n
i.x = m
i.p = e
e.x = m
e.p = b
assert n.p.x.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
m = A("m")
h = A("h")
c = A("c")
j = B("j")
b = B("b")
i = B("i")
e = B("e")

a.w = m
n.x = m
n.p = j
m.w = h
h.w = c
c.w = m
j.x = m
j.p = e
b.x = c
b.p = n
i.x = m
i.p = e
e.x = m
e.p = b
assert n.p.x.w.w.w.w.w.txt == "c"