#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int J[10001][1001], O[10001][1001], I[10001][1001];
int j[1001], o[1001], ai[1001];
int main() {
	long long n, w, k, b, c, d, e; char a; cin >> n >> w >> k;
	for (int h = 1; h <= n; h++) {
		int s = 0, t = 0, u = 0;
		for (int i = 1; i <= w; i++) {
			cin >> a;
			if (a == 'J') { s++; J[h][i] = j[i] + s; }
			else { J[h][i] = j[i] + s; }
			if (a == 'O') { t++; O[h][i] = o[i] + t; }
			else { O[h][i] = o[i] + t; }
			if (a == 'I') { u++; I[h][i] = ai[i] + u; }
			else { I[h][i] = ai[i] + u; }
			j[i] += s; o[i] += t; ai[i] += u;
		}
	}
	for (int h = 1; h <= k; h++) {
		cin >> b >> c >> d >> e;
		cout << J[d][e] - J[d][c - 1] - J[b - 1][e] + J[b - 1][c - 1] << ' ';
		cout << O[d][e] - O[d][c - 1] - O[b - 1][e] + O[b - 1][c - 1] << ' ';
		cout << I[d][e] - I[d][c - 1] - I[b - 1][e] + I[b - 1][c - 1] << endl;
	}
	cin >> n;
}
