#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int M,N,K;
int planet[1005][1005][3] = {};

int ijoi(char c){
	switch(c){
		case 'J':
			return 0;
		case 'O':
			return 1;
		case 'I':
			return 2;
	}
	cout << "err" << endl;
	return -1;
}

void add(int i,const char *line){
	int joi[3] = {};
	for(int k=0;k<N;++k){
		joi[ijoi(line[k])]++;
		copy(joi,joi+3,planet[i][k+1]);
	}
}

int main(){
	cin >> M >> N >> K;
	for(int i=0;i<M;++i){
		char buf[10005];
		scanf("%s",buf);
		add(i,buf);
	}

	for(int i=0;i<K;++i){
		int m1,n1,m2,n2;
		int joi[3] = {};
		cin >> m1 >> n1 >> m2 >> n2;
		for(int k=m1-1;k<m2;++k){
			for(int j=0;j<3;++j){
				joi[j] += planet[k][n2][j] - planet[k][n1-1][j];
			}
		}
		printf("%d %d %d\n",joi[0],joi[1],joi[2]);
	}
	return 0;
}