#include<cstdio>
#include<iostream>
#include<algorithm>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

using namespace std;

char cell[1001][1001];
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];

int main(void){
	
	int n,m, k;
	
	scanf("%d%d", &m, &n);
	scanf("%d", &k);
	
	rep(i,m)scanf("%s", cell[i]);
	
	reps(i,1,m+1)reps(j,1,n+1){
		J[i][j] = J[i-1][j]+J[i][j-1]-J[i-1][j-1]+(cell[i-1][j-1]=='J');
		O[i][j] = O[i-1][j]+O[i][j-1]-O[i-1][j-1]+(cell[i-1][j-1]=='O');
		I[i][j] = I[i-1][j]+I[i][j-1]-I[i-1][j-1]+(cell[i-1][j-1]=='I');
	}
	
	/*
	reps(i,1,m+1){
		reps(j,1,n+1){
			printf("(%d %d %d)", J[i][j], O[i][j], I[i][j]);
		}puts("");
	}
	*/
	int a,b,c,d;
	
	rep(i,k){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		int jt = J[c][d] + J[a-1][b-1];
		int ot = O[c][d] + O[a-1][b-1];
		int it = I[c][d] + I[a-1][b-1];
		
		jt =jt-(J[a-1][d]+J[c][b-1]);
		ot =ot-(O[a-1][d]+O[c][b-1]);
		it =it-(I[a-1][d]+I[c][b-1]);
		printf("%d %d %d\n", jt, ot, it);
	}
	
	return 0;
	
}