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

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

k = A("k")
a = B("a")
n = A("n")
h = A("h")
j = A("j")
m = A("m")
i = B("i")

k.p = a
k.o = h
a.t = i
a.s = i
n.p = a
n.o = m
h.p = a
h.o = k
j.p = a
j.o = h
m.p = a
m.o = n
i.t = a
i.s = a
assert a.s.s.s.t.t.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.o: A = None
        self.txt = txt

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

k = A("k")
a = B("a")
n = A("n")
h = A("h")
j = A("j")
m = A("m")
i = B("i")

k.p = a
k.o = h
a.t = i
a.s = i
n.p = a
n.o = m
h.p = a
h.o = k
j.p = a
j.o = h
m.p = a
m.o = n
i.t = a
i.s = a
assert a.s.s.s.t.t.s.t.txt == "i"