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

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

m = A("m")
h = B("h")
l = B("l")
c = A("c")
k = A("k")
n = B("n")
e = B("e")
f = A("f")
a = A("a")
g = A("g")

m.t = h
h.s = n
l.s = n
c.t = e
k.t = l
n.s = h
e.s = l
f.t = e
a.t = l
g.t = l
assert l.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

m = A("m")
h = B("h")
l = B("l")
c = A("c")
k = A("k")
n = B("n")
e = B("e")
f = A("f")
a = A("a")
g = A("g")

m.t = h
h.s = n
l.s = n
c.t = e
k.t = l
n.s = h
e.s = l
f.t = e
a.t = l
g.t = l
assert l.s.s.s.s.s.s.s.txt == "n"