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

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

a = A("a")
b = B("b")
c = B("c")
l = B("l")
n = B("n")
j = A("j")
f = A("f")
m = B("m")
d = B("d")

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

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

a = A("a")
b = B("b")
c = B("c")
l = B("l")
n = B("n")
j = A("j")
f = A("f")
m = B("m")
d = B("d")

a.p = j
b.s = j
b.w = c
c.s = f
c.w = d
l.s = j
l.w = n
n.s = j
n.w = m
j.p = f
f.p = a
m.s = a
m.w = l
d.s = j
d.w = b
assert c.s.p.p.p.p.p.txt == "j"