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

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

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

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

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

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

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