using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int h = inpt[0];
        int w = inpt[1];

        int queryCount = int.Parse(Reader.ReadLine());

        int[,] jCount = new int[h, w];
        int[,] oCount = new int[h, w];
        int[,] iCount = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            string txt = Reader.ReadLine();
            for (int j = 0; j < w; j++)
            {
                char c = txt[j];
                if (i > 0)
                {
                    jCount[i, j] = jCount[i - 1, j];
                    oCount[i, j] = oCount[i - 1, j];
                    iCount[i, j] = iCount[i - 1, j];
                }
                if (j > 0)
                {
                    jCount[i, j] += jCount[i, j - 1];
                    oCount[i, j] += oCount[i, j - 1];
                    iCount[i, j] += iCount[i, j - 1];
                }
                if (i > 0 && j > 0)
                {
                    jCount[i, j] -= jCount[i - 1, j - 1];
                    oCount[i, j] -= oCount[i - 1, j - 1];
                    iCount[i, j] -= iCount[i - 1, j - 1];

                }
                if (c == 'J')
                {
                    jCount[i, j]++;
                }
                else if (c == 'O')
                {
                    oCount[i, j]++;
                }
                else
                {
                    iCount[i, j]++;
                }
            }
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < queryCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            int r1 = inpt[0];
            int c1 = inpt[1];
            int r2 = inpt[2];
            int c2 = inpt[3];

            int j = this.GetCount(jCount, r1, c1, r2, c2);
            int o = this.GetCount(oCount, r1, c1, r2, c2);
            int ii = this.GetCount(iCount, r1, c1, r2, c2);

            ans.AppendLine(j + " " + o + " " + ii);
        }
        Console.Write(ans.ToString());

    }

    private int GetCount(int[,] arr, int r1, int c1, int r2, int c2)
    {
        int ans = arr[r2 - 1, c2 - 1];

        if (c1 > 1)
        {
            ans -= arr[r2 - 1, c1 - 2];
        }
        if (r1 > 1)
        {
            ans -= arr[r1 - 2, c2 - 1];
        }
        if (c1 > 1 && r1 > 1)
        {
            ans += arr[r1 - 2, c1 - 2];
        }
        return ans;
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


4 7
4
JIOJOIJ
IOJOIJO
JOIJOOI
OOJJIJO
3 5 4 7
2 2 3 6
2 2 2 2
1 1 4 7



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 47060