#include <cstdio>

int J[1000][1000];
int O[1000][1000];
int I[1000][1000];

int res[100000][3];

int main() {
	int m, n, k;
	scanf("%d%d", &m, &n);
	scanf("%d", &k);
	
	char s[n+1];
	for(int i=0;i<m+1;i++) {
		J[i][0] = 0;
		O[i][0] = 0;
		I[i][0] = 0;
	}
	for(int j=0;j<n+1;j++) {
		J[0][j] = 0;
		O[0][j] = 0;
		I[0][j] = 0;
	}
	for(int i=1;i<m+1;i++) {
		scanf("%s", s);
		for(int j=1;j<n+1;j++) {
			J[i][j] = J[i][j-1]+(s[j-1]=='J'?1:0);
			O[i][j] = O[i][j-1]+(s[j-1]=='O'?1:0);
			I[i][j] = I[i][j-1]+(s[j-1]=='I'?1:0);
		}
	}
	
	
	int im[2], in[2];
	int lm, sm, ln, sn;
	for(int i=0;i<k;i++) {
		scanf("%d %d %d %d", &im[0], &in[0], &im[1], &in[1]);
		lm = (im[0]>im[1]?im[0]:im[1]);
		sm = (im[0]<im[1]?im[0]:im[1]);
		ln = (in[0]>in[1]?in[0]:in[1]);
		sn = (in[0]<in[1]?in[0]:in[1]);
		res[i][0] = 0;
		res[i][1] = 0;
		res[i][2] = 0;
		for(int j=sm;j<lm+1;j++) {
			res[i][0] += J[j][ln]-J[j][sn-1];
			res[i][1] += O[j][ln]-O[j][sn-1];
			res[i][2] += I[j][ln]-I[j][sn-1];
		}
	}
	
	for(int i=0;i<k;i++) {
		printf("%d %d %d\n", res[i][0], res[i][1], res[i][2]);
	}
	
	return  0;
}