#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_M = 1000;
static const int MAX_N = 1000;

int M, N, K;
char s[MAX_M][MAX_N + 1];
int memo[3][MAX_M + 1][MAX_N + 1];

int main(){
	cin >> M >> N >> K;
	for(int i = 0; i < M; i++) cin >> s[i];
	fill(memo[0][0], memo[3][0], 0);
	for(int i = 0; i < M; i++){
		for(int j = 0; j < N; j++){
			if(s[i][j] == 'J') memo[0][i + 1][j + 1]++;
			if(s[i][j] == 'O') memo[1][i + 1][j + 1]++;
			if(s[i][j] == 'I') memo[2][i + 1][j + 1]++;
		}
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j <= M; j++){
			for(int k = 0; k <= N; k++){
				if(k == 0) continue;
				memo[i][j][k] += memo[i][j][k - 1];
			}
		}
		for(int j = 0; j <= N; j++){
			for(int k = 0; k <= M; k++){
				if(k == 0) continue;
				memo[i][k][j] += memo[i][k - 1][j];
			}
		}
	}
	for(int i = 0; i < K; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--;
		for(int j = 0; j < 3; j++){
			cout << memo[j][c][d] - memo[j][c][b] - memo[j][a][d] + memo[j][a][b];
			if(j == 2) cout << endl;
			else cout << ' ';
		}
	}
	return 0;
}
