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

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

k = A("k")
d = B("d")
c = B("c")
i = B("i")
a = A("a")
l = B("l")
f = B("f")
n = A("n")
h = B("h")
b = A("b")

k.w = a
k.t = a
d.o = b
c.o = n
i.o = k
a.w = k
a.t = n
l.o = a
f.o = k
n.w = k
n.t = b
h.o = a
b.w = k
b.t = a
assert k.w.w.w.t.w.t.w.t.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.t: A = None
        self.txt = txt

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

k = A("k")
d = B("d")
c = B("c")
i = B("i")
a = A("a")
l = B("l")
f = B("f")
n = A("n")
h = B("h")
b = A("b")

k.w = a
k.t = a
d.o = b
c.o = n
i.o = k
a.w = k
a.t = n
l.o = a
f.o = k
n.w = k
n.t = b
h.o = a
b.w = k
b.t = a
assert k.w.w.w.t.w.t.w.t.w.w.txt == "a"