#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
int J[1005][1005],O[1005][1005],I[1005][1005];
using namespace std;
int main(){
	int N,M,K;
	cin>>N>>M;
	cin>>K;
	int cntJ=0,cntO=0,cntI=0;
	char a;
	memset(J,0,sizeof(J));
	memset(O,0,sizeof(O));
	memset(I,0,sizeof(I));
	for(int i=1;i<=N;i++){
		cntJ=0;
		cntO=0;
		cntI=0;
		for(int j=1;j<=M;j++){
			cin>>a;
			if(a=='J')cntJ++;
			if(a=='O')cntO++;
			if(a=='I')cntI++;
				J[i][j] = J[i-1][j]+cntJ;
				O[i][j] = O[i-1][j]+cntO;
			I[i][j] = I[i-1][j]+cntI;
		}
	}
	int aa,bb,cc,dd;
	for(int k=0;k<K;k++){
		cin>>aa>>bb>>cc>>dd;
	
	/*}
	for(int k=0;k<K;k++){*/
		cout<<J[cc][dd]+J[aa-1][bb-1]-J[aa-1][dd]-J[cc][bb-1]<<" ";
		cout<<O[cc][dd]+O[aa-1][bb-1]-O[aa-1][dd]-O[cc][bb-1]<<" ";
		cout<<I[cc][dd]+I[aa-1][bb-1]-I[aa-1][dd]-I[cc][bb-1]<<endl;
	}
}