
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x) for(int i = 0;i < x;++i)
#define FOR(i,x,y) for(int i = x;i < y;++i)
#define ALL(a) a.begin(),a.end()
using ll = long long;

int m,n,k;
inline int hash_(char c)
{
    return ((c=='J')?0:((c=='O')?1:2));
}
int imos[3][1234][1234];

int main()
{
    cin >> m >> n;
    cin >> k;
    REP(i,m)
    {
        char str[1234];
        cin >> str;
        REP(j,n)
        {
            int id = hash_(str[j]);
            imos[id][i+1][j+1] = 1;
        }
    }
    REP(id,3)
    {
        REP(j,n+1)
        {
            REP(i,m+1)
            {
                imos[id][i + 1][j] += imos[id][i][j];
            }
        }
    }
    REP(id,3)
    {
        REP(j,n+1)
        {
            REP(i,m+1)
            {
                imos[id][i][j + 1] += imos[id][i][j];
            }
        }
    }
    REP(i,k)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        --a;--b;
        REP(id,3)
        {
            int ans = imos[id][c][d] + imos[id][a][b] - imos[id][a][d] - imos[id][c][b];
            cout << ans << " \n"[id == 2];
        }
    }
    return 0;
}