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

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

e = A("e")
k = B("k")
b = B("b")
n = A("n")
h = B("h")
d = B("d")
f = A("f")
l = A("l")

e.s = f
e.w = l
k.y = l
b.y = n
n.s = l
n.w = l
h.y = f
d.y = e
f.s = n
f.w = l
l.s = e
l.w = e
assert d.y.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.w: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
b = B("b")
n = A("n")
h = B("h")
d = B("d")
f = A("f")
l = A("l")

e.s = f
e.w = l
k.y = l
b.y = n
n.s = l
n.w = l
h.y = f
d.y = e
f.s = n
f.w = l
l.s = e
l.w = e
assert d.y.w.s.txt == "e"