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

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

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

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

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

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

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