#include<stdio.h>
int J[1002][1002],O[1002][1002],I[1002][1002];
int a[100001],b[100001],c[100001],d[100001];
char joi[1001][1001];
int main(void)
{
	int M,N,K,i,j,sumJ,sumO,sumI;
	scanf("%d%d%d",&M,&N,&K);
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			scanf(" %c",&joi[i][j]);
		}
	}
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			J[i][j]=0;
			O[i][j]=0;
			I[i][j]=0;
		}
	}
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			if(joi[i][j]=='J'){
				J[i][j]++;
			}
			if(joi[i][j]=='O'){
				O[i][j]++;
			}
			if(joi[i][j]=='I'){
				I[i][j]++;
			}
			J[i][j+1]+=J[i][j];
			O[i][j+1]+=O[i][j];
			I[i][j+1]+=I[i][j];
		}
	}
	for(i=1;i<=N;i++){
		for(j=1;j<M;j++){
			J[j+1][i]+=J[j][i];
			O[j+1][i]+=O[j][i];
			I[j+1][i]+=I[j][i];
		}
	}
	for(i=1;i<=K;i++){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	}
	for(i=1;i<=K;i++){
		sumJ=0;
			sumJ+=J[c[i]][d[i]];
			sumJ-=J[a[i]-1][d[i]];
			sumJ-=J[c[i]][b[i]-1];
			sumJ+=J[a[i]-1][b[i]-1];
		sumO=0;
			sumO+=O[c[i]][d[i]];
			sumO-=O[a[i]-1][d[i]];
			sumO-=O[c[i]][b[i]-1];
			sumO+=O[a[i]-1][b[i]-1];
		sumI=0;
			sumI+=I[c[i]][d[i]];
			sumI-=I[a[i]-1][d[i]];
			sumI-=I[c[i]][b[i]-1];
			sumI+=I[a[i]-1][b[i]-1];
		printf("%d %d %d\n",sumJ,sumO,sumI);
	}
	return 0;
}