#include <iostream>
#include <vector>

using namespace std;

int main() {
	int m, n;
	int k;
	cin >> m >> n;
	cin >> k;
	char q;
	vector< vector<int> > hyouJ(m+1, vector<int>(n+1));
	vector< vector<int> > hyouO(m+1, vector<int>(n+1));
	vector< vector<int> > hyouI(m+1, vector<int>(n+1));
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> q;
			hyouJ[i][j] = hyouJ[i][j-1]; 
			hyouO[i][j] = hyouO[i][j-1];
			hyouI[i][j] = hyouI[i][j-1];
			if (q == 'J') {
				hyouJ[i][j]++;
			} else if (q == 'O') {
				hyouO[i][j]++;
			} else {
				hyouI[i][j]++;
			}
		}
	}
	for (int i = 0; i < k; i++) {
		int counter[3] = {0};
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		for (int j = a; j <= c; j++) {
			counter[0] += (hyouJ[j][d]-hyouJ[j][b-1]);
			counter[1] += (hyouO[j][d]-hyouO[j][b-1]);
			counter[2] += (hyouI[j][d]-hyouI[j][b-1]);
		}
		cout << counter[0] << ' ' << counter[1] << ' ' << counter[2] << endl;
	}
	return 0;
}