#include <cstdio>

using namespace std;

#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)

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

int main()
{
	int N, M, K; scanf("%d %d %d", &N, &M, &K);

	rep1(i, N) rep1(j, M) {
		char c; scanf("\n%c", &c);
		if (c == 'J') J[i][j] = 1;
		if (c == 'O') O[i][j] = 1;
		if (c == 'I') I[i][j] = 1;
	}

	rep1(i, N) rep1(j, M) {
		J[i][j] += J[i][j - 1];
		O[i][j] += O[i][j - 1];
		I[i][j] += I[i][j - 1];
	}

	rep1(i, M) rep1(j, N) {
		J[j][i] += J[j - 1][i];
		O[j][i] += O[j - 1][i];
		I[j][i] += I[j - 1][i];
	}

	rep(ii, K) {
		int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
		int j = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
		int o = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
		int i = I[c][d] - I[a - 1][d] - I[c][b - 1] + I[a - 1][b - 1];
		printf("%d %d %d\n", j, o, i);
	}
}