import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_)
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  [m, n] <- map read <$> words <$> getLine
  k <- readLn
  solve m n k

solve :: Int -> Int -> Int -> IO ()
solve m n k = do
  dp <- VM.replicate ((m+1) * (n+1)) (0, 0, 0)
  forM_ [1..m] $ \i -> do
    s <- getLine
    forM_ (zip [1..n] s) $ \(j, c) -> do
      l <- VM.read dp ((n+1)*i+j-1)
      u <- VM.read dp ((n+1)*i+j-n-1)
      ul <- VM.read dp ((n+1)*i+j-n-2)
      VM.write dp ((n+1)*i+j) (addJoi (subJoi (addJoi u l) ul) (toJoi c))
  forM_ [1..k] $ \_ -> do
    [a, b, c, d] <- map read <$> words <$> getLine
    l <- VM.read dp (c*(n+1)+(b-1))
    u <- VM.read dp ((a-1)*(n+1)+d)
    ul <- VM.read dp ((a-1)*(n+1)+(b-1))
    ct <- VM.read dp (c*(n+1)+d)
    printJoi $ addJoi (subJoi ct (addJoi l u)) ul

type JOI = (Int, Int, Int)

addJoi :: JOI -> JOI -> JOI
addJoi (j1, o1, i1) (j2, o2, i2) = (j1+j2, o1+o2, i1+i2)

subJoi :: JOI -> JOI -> JOI
subJoi (j1, o1, i1) (j2, o2, i2) = (j1-j2, o1-o2, i1-i2)

toJoi :: Char -> JOI
toJoi 'J' = (1,0,0)
toJoi 'O' = (0,1,0)
toJoi 'I' = (0,0,1)

printJoi :: JOI -> IO ()
printJoi (j, o, i) = putStrLn . unwords . map show $ [j, o, i]

