#include<iostream>

using namespace std;

int J[1001][1001], O[1001][1001], I[1001][1001];
int main(){
    int M, N;
    cin>> M>> N;
    int K;
    cin>> K;
    string fld[M];
    for(int i=0; i<M; i++){
        cin>> fld[i];
    }

    for(int i=1; i<=M; i++){
        for(int j=1; j<=N; j++){
            if(fld[i-1][j-1]=='J') J[i][j]=1;
            if(fld[i-1][j-1]=='O') O[i][j]=1;
            if(fld[i-1][j-1]=='I') I[i][j]=1;
        }
    }
    for(int i=0; i<M; i++){
        for(int j=0; j<N; j++){
            J[i+1][j+1]+=J[i+1][j];
            O[i+1][j+1]+=O[i+1][j];
            I[i+1][j+1]+=I[i+1][j];
        }
    }
    for(int i=0; i<M; i++){
        for(int j=0; j<N; j++){
            J[i+1][j+1]+=J[i][j+1];
            O[i+1][j+1]+=O[i][j+1];
            I[i+1][j+1]+=I[i][j+1];
        }
    }

    for(int k=0; k<K; k++){
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        int j=J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1];
        int o=O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1];
        int i=I[c][d]-I[a-1][d]-I[c][b-1]+I[a-1][b-1];
        printf("%d %d %d\n", j, o, i);
    }

    return 0;
}