#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

inline int query(const vector<vector<int> >& mat, int a, int b, int c, int d) {
	return mat[c][d] - mat[c][b - 1] - mat[a - 1][d] + mat[a - 1][b - 1];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int h, w, k;
	cin >> h >> w >> k;

	vector<vector<int> > J(h + 1, vector<int>(w + 1, 0));
	vector<vector<int> > O(J), I(J);
	for(int i = 0; i < h; ++i) {
		string field;
		cin >> field;
		for(int j = 0; j < w; ++j) {
			switch(field[j]) {
			case 'J':
				++J[i + 1][j + 1];
				break;
			case 'O':
				++O[i + 1][j + 1];
				break;
			default:
				++I[i + 1][j + 1];
			}
		}
	}

	for(int i = 0; i <= h; ++i) {
		for(int j = 0; j < w; ++j) {
			J[i][j + 1] += J[i][j];
			O[i][j + 1] += O[i][j];
			I[i][j + 1] += I[i][j];
		}
	}

	for(int j = 0; j <= w; ++j) {
		for(int i = 0; i < h; ++i) {
			J[i + 1][j] += J[i][j];
			O[i + 1][j] += O[i][j];
			I[i + 1][j] += I[i][j];
		}
	}

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

		cout << query(J, a, b, c, d) << " ";
		cout << query(O, a, b, c, d) << " ";
		cout << query(I, a, b, c, d) << endl;
	}

	return EXIT_SUCCESS;
}