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

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

j = A("j")
k = B("k")
n = B("n")
l = A("l")
d = B("d")
m = A("m")
a = A("a")
i = A("i")
f = A("f")

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

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

j = A("j")
k = B("k")
n = B("n")
l = A("l")
d = B("d")
m = A("m")
a = A("a")
i = A("i")
f = A("f")

j.w = d
j.s = i
k.s = n
k.x = l
n.s = d
n.x = m
l.w = k
l.s = j
d.s = k
d.x = j
m.w = k
m.s = j
a.w = d
a.s = j
i.w = d
i.s = a
f.w = d
f.s = m
assert f.w.s.s.x.s.txt == "j"