#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int field[1010][1010][3];

int main()
{
	int M, N;  cin >> M >> N;
	int K; cin >> K;
	string str = "JOI";

	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= N; j++) {
			char c;
			cin >> c;
			for (int k = 0; k < 3; k++)
				field[i][j][k] = field[i - 1][j][k] + field[i][j - 1][k] - field[i - 1][j - 1][k];
			field[i][j][str.find(c)]++;
		}
	}
	for (int i = 0; i < K; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		for (int j = 0; j < 3; j++) {
			cout << field[c][d][j] + field[a - 1][b - 1][j] - field[a - 1][d][j] - field[c][b - 1][j];
			if (j != 2)cout << " ";
		}
		cout << endl;
	}
	return 0;
}