#include<iostream>
#include<cstring>

using namespace std;

int jj[1001][1001],oo[1001][1001],ii[1001][1001];
char map[1001][1001];

int main(void){
	int a,b,c,m,n,k;
	cin >> m >> n;
	cin >> k;
	for(a=0;a<m;a++){
		cin >> map[a];
	}
	memset(jj,0,sizeof(jj));
	memset(jj,0,sizeof(oo));
	memset(jj,0,sizeof(ii));
	for(a=0;a<m;a++){
		for(b=0;b<n;b++){
			jj[b+1][a+1]=jj[b+1][a]+jj[b][a+1]-jj[b][a];
			oo[b+1][a+1]=oo[b+1][a]+oo[b][a+1]-oo[b][a];
			ii[b+1][a+1]=ii[b+1][a]+ii[b][a+1]-ii[b][a];
			if(map[a][b]=='J')jj[b+1][a+1]++;
			if(map[a][b]=='O')oo[b+1][a+1]++;
			if(map[a][b]=='I')ii[b+1][a+1]++;
		}
	}
	for(c=0;c<k;c++){
		int ax,ay,bx,by;
		int ja=0,oa=0,ia=0;
		cin >> ay >> ax >> by >> bx;
		ja=jj[bx][by]-jj[ax-1][by]-jj[bx][ay-1]+jj[ax-1][ay-1];
		oa=oo[bx][by]-oo[ax-1][by]-oo[bx][ay-1]+oo[ax-1][ay-1];
		ia=ii[bx][by]-ii[ax-1][by]-ii[bx][ay-1]+ii[ax-1][ay-1];
		cout << ja << " " << oa << " " << ia << endl;
	}
	return 0;
}