#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int M, N, K;
string S[1001];
int A, B, C, D;
int I[1001][1001];
int O[1001][1001];
int J[1001][1001];
int main(){
	scanf("%d%d%d", &M, &N, &K);
	for (int i = 0; i < M; i++)cin >> S[i + 1];
	for (int i = 1; i <= M; i++){
		for (int j = 1; j <= N; j++){
			I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];
			O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
			J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
			if (S[i][j - 1] == 'J')J[i][j]++;
			if (S[i][j - 1] == 'O')O[i][j]++;
			if (S[i][j - 1] == 'I')I[i][j]++;
		}
	}
	for (int k = 0; k < K; k++){
		scanf("%d%d%d%d", &A, &B, &C, &D);
		printf("%d %d %d\n", J[C][D] - J[A - 1][D] - J[C][B - 1] + J[A - 1][B - 1], O[C][D] - O[A - 1][D] - O[C][B - 1] + O[A - 1][B - 1], I[C][D] - I[A - 1][D] - I[C][B - 1] + I[A - 1][B - 1]);
	}
	return 0;
}