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

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

a = A("a")
n = B("n")
m = A("m")
b = A("b")
k = B("k")
l = A("l")
i = B("i")
c = B("c")
f = B("f")

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

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

a = A("a")
n = B("n")
m = A("m")
b = A("b")
k = B("k")
l = A("l")
i = B("i")
c = B("c")
f = B("f")

a.s = m
a.p = m
n.w = a
m.s = a
m.p = b
b.s = m
b.p = l
k.w = l
l.s = b
l.p = a
i.w = a
c.w = a
f.w = b
assert m.p.p.p.p.p.s.p.p.p.txt == "a"