#include<iostream>
#include<utility>
using namespace std;
typedef pair<int, int>P;

P planet[1002][1002];

int main() {
	int m, n, k;
	cin >> m >> n;
	cin >> k;

	for (int i = 0;i<m;i++) {
		planet[i][0] = make_pair(0, 0);
		for (int j = 1;j<=n;j++) {
			char a;
			cin >> a;
			planet[i][j] = planet[i][j - 1];
			if (a == 'J')planet[i][j].first++;
			else if (a == 'O')planet[i][j].second++;
		}
	}

	for (int i = 0;i<k;i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int J = 0, O = 0, I = 0;
		for (int j = a - 1;j<c;j++) {
			int e = planet[j][d].first - planet[j][b - 1].first;
			int f = planet[j][d].second - planet[j][b - 1].second;
			J += e;
			O += f;
		}
		I = (c - a + 1)*(d - b + 1) - J - O;
		cout << J << ' ' << O << ' ' << I << endl;
	}
	return 0;
}