#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int M, N, K;
string grid[1009];
int jc[1009][1009] = {}, oc[1009][1009] = {}, ic[1009][1009] = {};


int main() {
	cin >> M >> N >> K;
	for (int i = 1; i <= M; i++) {
		cin >> grid[i];
		for (int j = 1; j <= N; j++) {
			if (grid[i][j-1] == 'J')jc[i][j]++;
			if (grid[i][j-1] == 'O')oc[i][j]++;
			if (grid[i][j-1] == 'I')ic[i][j]++;
			jc[i][j] += jc[i][j - 1] + jc[i - 1][j] - jc[i - 1][j - 1];
			oc[i][j] += oc[i][j - 1] + oc[i - 1][j] - oc[i - 1][j - 1];
			ic[i][j] += ic[i][j - 1] + ic[i - 1][j] - ic[i - 1][j - 1];
		}	
	}

	for (int i = 0; i < K; i++) {
		int i1, j1, i2, j2;
		cin >> i1 >> j1 >> i2 >> j2;
		int J, O, I;
		J = jc[i2][j2] - jc[i2][j1 - 1] - jc[i1 - 1][j2] + jc[i1 - 1][j1 - 1];
		O = oc[i2][j2] - oc[i2][j1 - 1] - oc[i1 - 1][j2] + oc[i1 - 1][j1 - 1];
		I = ic[i2][j2] - ic[i2][j1 - 1] - ic[i1 - 1][j2] + ic[i1 - 1][j1 - 1];
		cout << J << " " << O << " " << I << endl;
	}
	
	

	return 0;
}


