#include<stdio.h>
int m,n,k;
int f,g,h;
int a,b,c,d;
char map[1003][1003];
int j[1003][1003],o[1003][1003],i[1003][1003];
int main(void){
	scanf("%d %d",&m,&n);
	scanf("%d",&k);
	for(f=1;f<=m;f++){
		for(g=1;g<=n;g++){
			j[f][g]=0;
			o[f][g]=0;
			i[f][g]=0;
		}
	}
	for(f=1;f<=m;f++){
		for(g=1;g<=n;g++){
			scanf(" %c",&map[f][g]);
			if(map[f][g]=='J'){
				j[f][g]++;
			}
			else if(map[f][g]=='O'){
				o[f][g]++;
			}
			else if(map[f][g]=='I'){
				i[f][g]++;
			}
			j[f][g+1]+=j[f][g];
			o[f][g+1]+=o[f][g];
			i[f][g+1]+=i[f][g];
		}
	}
	for(g=1;g<=n;g++){
		for(f=1;f<=m;f++){
			j[f+1][g]+=j[f][g];
			o[f+1][g]+=o[f][g];
			i[f+1][g]+=i[f][g];
		}
	}
	int anj,ano,ani;
	for(f=0;f<k;f++){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		anj=j[c][d]-j[c][b-1]-j[a-1][d]+j[a-1][b-1];
		ano=o[c][d]-o[c][b-1]-o[a-1][d]+o[a-1][b-1];
		ani=i[c][d]-i[c][b-1]-i[a-1][d]+i[a-1][b-1];
		printf("%d %d %d\n",anj,ano,ani);
	}
	/*for(f=1;f<=m;f++){
		for(g=1;g<=n;g++){
			printf("%d,%d=%d%d%d ",f,g,j[f][g],o[f][g],i[f][g]);
		}
		printf("\n");
	}*/
	return 0;
}