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

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

k = A("k")
f = B("f")
i = B("i")
b = A("b")
j = B("j")
c = A("c")
m = B("m")
a = B("a")
g = B("g")
n = A("n")

k.z = n
k.s = n
f.o = j
i.o = j
b.z = c
b.s = k
j.o = f
c.z = n
c.s = k
m.o = a
a.o = m
g.o = i
n.z = c
n.s = c
assert k.z.z.s.z.z.z.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: A = None
        self.txt = txt

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

k = A("k")
f = B("f")
i = B("i")
b = A("b")
j = B("j")
c = A("c")
m = B("m")
a = B("a")
g = B("g")
n = A("n")

k.z = n
k.s = n
f.o = j
i.o = j
b.z = c
b.s = k
j.o = f
c.z = n
c.s = k
m.o = a
a.o = m
g.o = i
n.z = c
n.s = c
assert k.z.z.s.z.z.z.s.s.txt == "k"