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

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

n = A("n")
a = B("a")
b = B("b")
k = B("k")
i = B("i")

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

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

n = A("n")
a = B("a")
b = B("b")
k = B("k")
i = B("i")

n.w = k
a.t = k
a.o = k
b.t = a
b.o = a
k.t = i
k.o = b
i.t = b
i.o = k
assert i.o.t.o.txt == "k"