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

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

e = A("e")
m = B("m")
a = B("a")
i = A("i")
d = B("d")
h = B("h")
k = A("k")
l = A("l")
g = A("g")

e.s = a
m.w = d
a.w = d
i.s = m
d.w = a
h.w = d
k.s = h
l.s = d
g.s = a
assert m.w.w.w.w.w.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: B = None
        self.txt = txt

e = A("e")
m = B("m")
a = B("a")
i = A("i")
d = B("d")
h = B("h")
k = A("k")
l = A("l")
g = A("g")

e.s = a
m.w = d
a.w = d
i.s = m
d.w = a
h.w = d
k.s = h
l.s = d
g.s = a
assert m.w.w.w.w.w.w.txt == "a"