#include <iostream>
using namespace std;
int aj[1010][1010]={},ao[1010][1010]={},ai[1010][1010]={};
int main(){
	int M,N,K,a,b,c,d;
	char ch;
	cin>>M>>N>>K;
	for(int i=1;i<=M;i++){
		for(int j=1;j<=N;j++){
			cin>>ch;
			aj[i][j]=aj[i-1][j]+aj[i][j-1]-aj[i-1][j-1]+(ch=='J');
			ao[i][j]=ao[i-1][j]+ao[i][j-1]-ao[i-1][j-1]+(ch=='O');
			ai[i][j]=ai[i-1][j]+ai[i][j-1]-ai[i-1][j-1]+(ch=='I');
		}
	}
	
	for(int i=0;i<K;i++){
		cin>>a>>b>>c>>d;
		a--;b--;
		cout<<aj[a][b]+aj[c][d]-aj[a][d]-aj[c][b]<<" "<<ao[a][b]+ao[c][d]-ao[a][d]-ao[c][b]<<" "<<ai[a][b]+ai[c][d]-ai[a][d]-ai[c][b]<<endl;
	}
	return 0;
}