//Solution for aoj 0560:Planetary Exploration
#include <iostream>
using namespace std;
int n, m, k, res[3], mid, a, b;
int planet2[1001][1001][4], ex[4];
char planet[1001][1001];
int jud(char a){
	if (a == 'J')
		return 1;
	if (a == 'O')
		return 2;
	if (a == 'I')
		return 3;
}
int main(){
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> planet[i][j];
		}
	}
	planet2[1][1][jud(planet[1][1])] = 1;
	for (int i = 2; i <= n; i++){
		for (int j = 1; j<4; j++)
			planet2[i][1][j] = planet2[i - 1][1][j];
		planet2[i][1][jud(planet[i][1])]++;
	}
	for (int i = 2; i <= m; i++){
		for (int j = 1; j<4; j++)
			planet2[1][i][j] = planet2[1][i - 1][j];
		planet2[1][i][jud(planet[1][i])]++;
	}
	for (int i = 2; i <= n; i++){
		for (int j = 2; j <= m; j++){
			for (int l = 1; l<4; l++){
				planet2[i][j][l] = planet2[i - 1][j][l] + planet2[i][j - 1][l] - planet2[i - 1][j - 1][l];
			}
			planet2[i][j][jud(planet[i][j])]++;
		}
	}
	for (int i = 0; i<k; i++){
		for (int j = 0; j<4; j++){
			cin >> ex[j];
		}
		for (int j = 1; j<4; j++){
			cout << planet2[ex[2]][ex[3]][j] - planet2[ex[0] - 1][ex[3]][j] - planet2[ex[2]][ex[1] - 1][j] + planet2[ex[0] - 1][ex[1] - 1][j];
			if (j != 3)
				cout << ' ';
		}
		cout << endl;
	}
	return 0;
}