#include<iostream>
#include<string>

using namespace std;

#define NMAX 999
#define MMAX 999

int main(){

    int M,N;
    int K;
    int J[NMAX+1][MMAX+1]={0};
    int O[NMAX+1][MMAX+1]={0};
    int a,b,c,d;
    string in;

    cin>>M>>N;
    cin>>K;

    for(int i=1;i<=M;i++){
        cin>>in;
        for(int j=0;j<N;j++){
            if(in[j]=='J') J[i][j+1]=1;
            else if(in[j]=='O') O[i][j+1]=1;
            else if(in[j]=='I') I[i][j+1]=1;
        }
    }

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

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

    for(int i=0;i<K;i++){
        cin>>a>>b>>c>>d;
        cout<<J[c][d]-J[c][b-1]-J[a-1][d]+J[a-1][b-1]<<" "<<O[c][d]-O[c][b-1]-O[a-1][d]+O[a-1][b-1]<<" "<<I[c][d]-I[c][b-1]-I[a-1][d]+I[a-1][b-1]<<endl;
    }

    return 0;
}