#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;


#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

char board[1111][1111];
int csum[1111][1111][3];

int g(char c){
	if(c=='J')return 0;
	if(c=='O')return 1;
	return 2;
}

int main(){
	int w,h,qc;
	cin>>h>>w>>qc;
	
	rep(i,h){
		scanf("%s",&board[i]);
	}
	
	reps(i,1,h+1){
		reps(j,1,w+1){
			rep(k,3){
				csum[i][j][k] += csum[i][j-1][k];
				csum[i][j][k] += csum[i-1][j][k];
				csum[i][j][k] -= csum[i-1][j-1][k];
			}
			char c = board[i-1][j-1];
			csum[i][j][g(c)]++;
		}
	}
	
	rep(i,qc){
		int xst,yst,xen,yen;
		scanf("%d%d%d%d",&xst,&yst,&xen,&yen);
		
		rep(k,3){
			int ans=0;
			ans += csum[xen][yen][k];
			ans -= csum[xst-1][yen][k];
			ans -= csum[xen][yst-1][k];
			ans += csum[xst-1][yst-1][k];
			printf("%d",ans);
			if(k!=2)printf(" ");
		}puts("");
	}
}