#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int dp[3][1001][1001];
map<char,int>latte;
int main(){
    latte['J']=0;latte['O']=1;latte['I']=2;
    int n,m,x;
    cin>>n>>m>>x;
    for(int i=1;i<=n;i++){
        string str;
        cin>>str;
        for(int j=1;j<=m;j++){
            int idx=latte[str[j-1]];
            for(int k=0;k<3;k++){
                dp[k][i][j]=dp[k][i-1][j]+dp[k][i][j-1]-dp[k][i-1][j-1];
                if(idx==k)dp[k][i][j]++;
            }
        }
    }

    while(x--){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        for(int i=0;i<3;i++){
            if(i!=0)cout<<" ";

            int ans=dp[i][c][d]-dp[i][a-1][d]-dp[i][c][b-1]+dp[i][a-1][b-1];
            cout<<ans;
        }
        cout<<endl;
    }
    /*
    for(int k=0;k<3;k++){
        cout<<endl;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cout<<dp[k][i][j]<<" ";
            }
            cout<<endl;
        }
    }*/
    return 0;
}