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

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

e = A("e")
n = B("n")
l = B("l")
m = B("m")
i = A("i")
d = A("d")

e.t = d
e.w = m
n.w = m
l.w = n
m.w = l
i.t = e
i.w = m
d.t = i
d.w = l
assert n.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: B = None
        self.txt = txt

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

e = A("e")
n = B("n")
l = B("l")
m = B("m")
i = A("i")
d = A("d")

e.t = d
e.w = m
n.w = m
l.w = n
m.w = l
i.t = e
i.w = m
d.t = i
d.w = l
assert n.w.w.w.w.w.w.txt == "n"