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

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

a = A("a")
j = B("j")
f = B("f")
b = A("b")
h = B("h")
n = A("n")
i = B("i")
d = B("d")

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

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

a = A("a")
j = B("j")
f = B("f")
b = A("b")
h = B("h")
n = A("n")
i = B("i")
d = B("d")

a.w = b
a.p = n
j.w = a
j.s = i
f.w = a
f.s = d
b.w = a
b.p = n
h.w = a
h.s = j
n.w = b
n.p = b
i.w = a
i.s = j
d.w = b
d.s = j
assert b.w.p.w.w.p.w.w.p.txt == "n"