#include<iostream>
using namespace std;

int m, n, k, aj[1001][1001], ao[1001][1001], ai[1001][1001];
int main()
{
	cin >> m >> n >> k;
	for (int i = 1; i <= m; i++){
		for (int j = 1; j <= n; j++){
			char in;
			cin >> in;
			aj[i][j] = aj[i - 1][j] + aj[i][j - 1] - aj[i - 1][j - 1];
			ao[i][j] = ao[i - 1][j] + ao[i][j - 1] - ao[i - 1][j - 1];
			ai[i][j] = ai[i - 1][j] + ai[i][j - 1] - ai[i - 1][j - 1];
			if (in == 'J') aj[i][j]++;
			else if (in == 'O') ao[i][j]++;
			else ai[i][j]++;
		}
	}

	for (int i = 0; i < k; i++){
		int a, b, c, d, ansj, anso, ansi;
		cin >> a >> b >> c >> d;
		a--; b--;
		ansj = aj[c][d] - aj[c][b] - aj[a][d] + aj[a][b];
		anso = ao[c][d] - ao[c][b] - ao[a][d] + ao[a][b];
		ansi = ai[c][d] - ai[c][b] - ai[a][d] + ai[a][b];
		cout << ansj << " " << anso << " " << ansi << endl;
	}
	return 0;
}