#include <iostream>
using namespace std;
#define FOR(i,a) for(i=0;i<a;i++)
int a[1000][1000][3];
int i,j;
int main() {
	int n,m;
	cin>>m>>n;
	int k;
	cin>>k;
	FOR(i,m){
		FOR(j,n){
			char p;
			cin>>p;
			if(i!=0 and j!=0){
				a[i][j][0]=a[i][j-1][0]+a[i-1][j][0]-a[i-1][j-1][0];
				a[i][j][1]=a[i][j-1][1]+a[i-1][j][1]-a[i-1][j-1][1];
				a[i][j][2]=a[i][j-1][2]+a[i-1][j][2]-a[i-1][j-1][2];
			}
			else if(i!=0){
				a[i][j][0]=a[i-1][j][0];
				a[i][j][1]=a[i-1][j][1];
				a[i][j][2]=a[i-1][j][2];
			}
			else if(j!=0){
				a[i][j][0]=a[i][j-1][0];
				a[i][j][1]=a[i][j-1][1];
				a[i][j][2]=a[i][j-1][2];
			}
			if(p=='J'){
				a[i][j][0]++;
			}
			if(p=='O'){
				a[i][j][1]++;
			}
			if(p=='I'){
				a[i][j][2]++;
			}
		}
	}
/*	FOR(i,m){
		FOR(j,n){
			cout<<a[i][j][0]<<" ";
		}
		cout<<endl;
	}*/
	FOR(i,k){
		int q,w,e,r;
		cin>>q>>w>>e>>r;
		FOR(j,3){
			int ans=a[e-1][r-1][j];
			if(q-2>=0 and w-2>=0){ans=ans+a[q-2][w-2][j]-a[e-1][w-2][j]-a[q-2][r-1][j];}
			else if(w-2>=0){ans=ans-a[e-1][w-2][j];}
			else if(q-2>=0){ans=ans-a[q-2][r-1][j];}
			cout<<ans;
			if(j<2){
				cout<<" ";	
			}
			else{
				cout<<endl;
			}
		}
	}
	return 0;
}