#include <cstdio>

#define fo(x,y,z) for(int (x)=y;x<z;x++)

int m,n,k,c[1005][1005][3];
char ma[1005][1005];

int f(int a){
	return (a>=0)?a:1004;
}

int main(){
	scanf("%d%d%d ",&m,&n,&k);
	fo(i,0,m){
		scanf(" %s ",ma[i]);
		fo(j,0,n){
			if(ma[i][j]=='J') c[i][j][0]++;
			else if(ma[i][j]=='O') c[i][j][1]++;
			else c[i][j][2]++;
			fo(x,0,3)
				c[i][j][x]+=c[i][f(j-1)][x];
		}
	}

	fo(i,0,m)
		fo(j,0,n)
			fo(x,0,3)
				c[i][j][x]+=c[f(i-1)][j][x];

	int lx,ly,rx,ry;
	fo(i,0,k){
		scanf("%d%d%d%d",&lx,&ly,&rx,&ry);
		lx--;ly--;rx--;ry--;
		fo(x,0,3){
			printf("%d",c[rx][ry][x]-c[f(lx-1)][ry][x]-c[rx][f(ly-1)][x]+c[f(lx-1)][f(ly-1)][x]);
			if(x<2) printf(" ");
		}
		printf("\n");
	}
	return 0;
}