#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 1002
//#define mp make_pair
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int b[MAX][MAX][6];
char a[MAX][MAX];
string str[MAX];
char c[3] = {'J', 'O', 'I'};
stack<int> st;
int main(){
	int h, w, k;
	scanf("%d%d%d", &h, &w, &k);
	rep(i,h)cin >> str[i];
	rep(i,h)rep(j,w)a[i+1][j+1] = str[i][j];
	rep(i,h)rep(j,w)rep(u,3){
		if(a[i+1][j+1] == c[u])b[i+1][j+1][u]++;
		b[i+1][j+1][u] += b[i+1][j][u];
	}
	rep(i,h)rep(j,w)rep(u,3){
		b[i+1][j+1][u+3] = b[i][j+1][u+3] + b[i+1][j+1][u];
	}
	
	int x[4], y[3];
	for(int i = 0;i < k;i++){
		rep(j,4)scanf("%d", &x[j]);
		x[0]--;x[1]--;
		rep(u,3)
		y[u] = b[x[2]][x[3]][u+3]+b[x[0]][x[1]][u+3]-b[x[2]][x[1]][u+3]-b[x[0]][x[3]][u+3];
		printf("%d %d %d\n", y[0], y[1], y[2]);
	}
	
	return 0;
}