#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int dp[1010][1010][3]={0};
int main(){
	char tmp[3]={'J','O','I'};
	int a,b,n;
	cin>>a>>b>>n;
	vector<string>in(a);
	rep(i,a)cin>>in[i];
	loop(i,1,a+1)loop(j,1,b+1)rep(k,3){
		dp[i][j][k]=dp[i-1][j][k]+dp[i][j-1][k]-dp[i-1][j-1][k];
		if((char)in[i-1][j-1]==tmp[k])dp[i][j][k]++;
	}
	rep(i,n){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int out[3]={0};
		rep(j,3)out[j]=dp[c][d][j]-dp[c][b-1][j]-dp[a-1][d][j]+dp[a-1][b-1][j];
		cout<<out[0]<<" "<<out[1]<<" "<<out[2]<<endl;
	}
}