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

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

k = A("k")
j = B("j")
i = B("i")
g = A("g")
b = A("b")
f = B("f")
d = B("d")
l = A("l")
e = A("e")
m = B("m")

k.s = m
j.w = e
i.w = e
g.s = m
b.s = d
f.w = b
d.w = e
l.s = j
e.s = m
m.w = l
assert l.s.w.s.w.s.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k = A("k")
j = B("j")
i = B("i")
g = A("g")
b = A("b")
f = B("f")
d = B("d")
l = A("l")
e = A("e")
m = B("m")

k.s = m
j.w = e
i.w = e
g.s = m
b.s = d
f.w = b
d.w = e
l.s = j
e.s = m
m.w = l
assert l.s.w.s.w.s.w.s.w.txt == "l"