#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int map_j[2000][2000], map_o[2000][1500], map_i[1200][1300];
signed main() {
	int h, w, n; cin >> h >> w >> n;
	for (int i = 1; i <= h; i++) {
		string s; cin >> s;
		for (int j = 1; j <= w; j++) {
			map_j[i][j] = map_j[i - 1][j] + map_j[i][j - 1] - map_j[i - 1][j - 1]; if (s[j - 1] == 'J')map_j[i][j]++;
			map_o[i][j] = map_o[i - 1][j] + map_o[i][j - 1] - map_o[i - 1][j - 1]; if (s[j - 1] == 'O')map_o[i][j]++;
			map_i[i][j] = map_i[i - 1][j] + map_i[i][j - 1] - map_i[i - 1][j - 1]; if (s[j - 1] == 'I')map_i[i][j]++;
		}
	}
	for (int i = 0; i < n; i++) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		a--; b--;
		cout << map_j[c][d] - map_j[c][b] - map_j[a][d] + map_j[a][b] << ' ';
		cout << map_o[c][d] - map_o[c][b] - map_o[a][d] + map_o[a][b] << ' ';
		cout << map_i[c][d] - map_i[c][b] - map_i[a][d] + map_i[a][b] << endl;
	}
}
