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

using namespace std;

#define rep(i,a,n) for(int i = a; n > i; i++)
#define REP(i,n) rep(i,0,n)

#define ALL(a) (a).begin(),(a).end()


int rui[3][1002][1002] = {};

int main(){
	int n,m,k;
	scanf("%d %d %d", &n, &m, &k);


	REP(i,n){
		scanf("%*c");
		REP(j,m){
			char buf;
			scanf("%c", &buf);
			switch(buf){
			case 'J':
				rui[0][i+1][j+1]++;
				break;

			case 'O':
				rui[1][i+1][j+1]++;
				break;

			case 'I':
				rui[2][i+1][j+1]++;
				break;
			}
		}
	}
	REP(i,n){
		REP(j,m){
			rui[0][i+2][j+1] += rui[0][i+1][j+1];
			rui[1][i+2][j+1] += rui[1][i+1][j+1];
			rui[2][i+2][j+1] += rui[2][i+1][j+1];
		}
	}
	REP(i,n){
		REP(j,m){
			rui[0][i+1][j+2] += rui[0][i+1][j+1];
			rui[1][i+1][j+2] += rui[1][i+1][j+1];
			rui[2][i+1][j+2] += rui[2][i+1][j+1];
		}
	}

	REP(i,k){
		int a,b,c,d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		//a--;b--;c--;d--;
		REP(j,3){
			int res = rui[j][c][d] - rui[j][a-1][d] - rui[j][c][b-1] + rui[j][a-1][b-1];
			printf("%d",res);
			if(j < 2)
				printf(" ");
		}
		printf("\n");
	}


	return 0;
}