// 2012/02/18 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int M, N;
	cin >> M >> N;

	int K;
	cin >> K;

	int J[1001][1001];
	int O[1001][1001];
	for(int y=0; y<=M; y++){
		J[y][0] = 0;
		O[y][0] = 0;
	}
	for(int x=0; x<=N; x++){
		J[0][x] = 0;
		O[0][x] = 0;
	}

	for(int y=1; y<=M; y++){
		for(int x=1; x<=N; x++){
			char c;
			cin >> c;

			J[y][x] = J[y-1][x]+J[y][x-1]-J[y-1][x-1];
			O[y][x] = O[y-1][x]+O[y][x-1]-O[y-1][x-1];

			if(c=='J'){
				J[y][x]++;
			}
			else if(c=='O'){
				O[y][x]++;
			}
		}
	}

	for(int i=0; i<K; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int cntJ = J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1];
		int cntO = O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1];
		int cntI = (c-a+1)*(d-b+1)-cntJ-cntO;

		cout << cntJ << ' ' << cntO << ' ' << cntI << endl;
	}

	return 0;
}