#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int M, N, K; 
int J[1001][1001], O[1001][1001], I[1001][1001];
string s[1000];

int main() {
	cin >> M >> N >> K;
	for (int i = 0; i < M; i++) {
		cin >> s[i];
	}

	for (int i = 0; i <= M; i++) {
		J[i][0] = 0;
		O[i][0] = 0;
		I[i][0] = 0;
	}
	for (int i = 0; i <= N; i++) {
		J[0][i] = 0;
		O[0][i] = 0;
		I[0][i] = 0;
	}

	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= N; j++) {
			J[i][j] = J[i][j - 1] + J[i - 1][j] - J[i - 1][j - 1];
			O[i][j] = O[i][j - 1] + O[i - 1][j] - O[i - 1][j - 1];
			I[i][j] = I[i][j - 1] + I[i - 1][j] - I[i - 1][j - 1];

			if (s[i-1][j-1] == 'J') {
				J[i][j]++;
			}
			if (s[i-1][j-1] == 'O') {
				O[i][j]++;
			}
			if (s[i-1][j-1] == 'I') {
				I[i][j]++;
			}
		}
	}


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

		int Jn = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
		int On = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
		int In = I[c][d] - I[a - 1][d] - I[c][b - 1] + I[a - 1][b - 1];

		cout << Jn << " " << On << " " << In << endl;
	}


	return 0;
}


