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

namespace Planetary_Exploration
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var input = line.Split(' ');
            int M = Int32.Parse(input[0]);
            int N = Int32.Parse(input[1]);

            line = Console.ReadLine();
            int K = Int32.Parse(line);

            int[,,] x  = new int[M,N,3];


            for (int i = 0; i < M; i++)
            {
                int totalJ = 0;
                int totalO = 0;
                int totalI = 0;
                line = Console.ReadLine();
                for (int j = 0; j < N; j ++)
                {
                    var c = line[j];
                    switch (c)
                    {
                        case 'J':
                            totalJ++;
                            break;
                        case 'O':
                            totalO++;
                            break;
                        case 'I':
                            totalI++;
                            break;
                    }
                    x[i, j, 0] = i == 0 ? totalJ : (x[i - 1, j, 0] + totalJ);
                    x[i, j, 1] = i == 0 ? totalO : (x[i - 1, j, 1] + totalO);
                    x[i, j, 2] = i == 0 ? totalI : (x[i - 1, j, 2] + totalI);
                }
            }

            for (int i = 0; i < K; i++)
            {
                line = Console.ReadLine();
                input = line.Split(' ');
                int a = Int32.Parse(input[0]) - 1;
                int b = Int32.Parse(input[1]) - 1;
                int c = Int32.Parse(input[2]) - 1;
                int d = Int32.Parse(input[3]) - 1;
                int J = x[c, d, 0] - (a > 0 ? x[a - 1, d, 0] : 0) - (b > 0 ? x[c, b - 1, 0] : 0) + (a > 0 && b > 0 ? x[a - 1, b - 1, 0] : 0);
                int O = x[c, d, 1] - (a > 0 ? x[a - 1, d, 1] : 0) - (b > 0 ? x[c, b - 1, 1] : 0) + (a > 0 && b > 0 ? x[a - 1, b - 1, 1] : 0);
                int I = x[c, d, 2] - (a > 0 ? x[a - 1, d, 2] : 0) - (b > 0 ? x[c, b - 1, 2] : 0) + (a > 0 && b > 0 ? x[a - 1, b - 1, 2] : 0);
                Console.WriteLine("" + J + " " + O + " " + I);
            }
        }
    }
}