ioi n = 'I':(concat $ replicate n "OI")

srch _ _ [] = 0
srch n p s@(_:ss) =
  let s'= take n s
      r = if s' == p
          then 1
          else 0
  in
    r + srch n p ss

ans :: [String] -> [Int]
ans ("0":_) = []
ans (n:_:s:xs) =
  let n' = read n :: Int
      p  = ioi n'
      r  = srch (2*n'+1) p s
  in
    r:(ans xs)

main = do
  c <- getContents
  let i = lines c
      o = ans i
  mapM_ print o