#include <iostream>
using namespace std;

const int MAX_M = 1000;
const int MAX_N = 1000;
const int MAX_K = 100000;
int jn[MAX_M][MAX_N] = {};
int on[MAX_M][MAX_N] = {};
int in[MAX_M][MAX_N] = {};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int m, n;
	cin >> m >> n;
	
	int k;
	cin >> k;
	
	for(int i = 1; i <= m; ++i){
		for(int j = 1; j <= n; ++j){
			char c;
			cin >> c;
			
			jn[i][j] += jn[i - 1][j] + jn[i][j - 1] - jn[i - 1][j - 1];
			on[i][j] += on[i - 1][j] + on[i][j - 1] - on[i - 1][j - 1];
			in[i][j] += in[i - 1][j] + in[i][j - 1] - in[i - 1][j - 1];
			
			if(c == 'J') jn[i][j]++;
			if(c == 'O') on[i][j]++;
			if(c == 'I') in[i][j]++;
		}
	}
		
	for(int i = 0; i < k; ++i){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int ansj = jn[c][d] - jn[c][b - 1] - jn[a - 1][d] + jn[a - 1][b - 1];
		int anso = on[c][d] - on[c][b - 1] - on[a - 1][d] + on[a - 1][b - 1];
		int ansi = in[c][d] - in[c][b - 1] - in[a - 1][d] + in[a - 1][b - 1];
		cout << ansj << " " << anso << " " << ansi << endl;
	}
	
	return 0;
}