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

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

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

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

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

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

k.s = i
a.o = i
c.o = k
n.o = f
i.s = k
f.s = i
m.o = k
assert k.s.s.s.s.txt == "k"