#include<iostream>
using namespace std;

#define M 1000

int main() {
	char map[M+1][M+1];
	char field[4] = "JOI";
	static int dp[3][M+1][M+1], temp[3], ans;
	int m, n, k, a, b, c, d;
	cin >> m >> n >> k;
	for(int i=1; i<=m; ++i) {
		for(int j=1; j<=n; ++j) cin >> map[i][j];
	}
	for(int p=0; p<3; ++p) {
		for(int i=0; i<m+1; ++i) dp[p][i][0] = 0;
		for(int j=0; j<n+1; ++j) dp[p][0][j] = 0;
	}
	for(int i=1; i<=m; ++i) {
		for(int p=0; p<3; ++p) temp[p] = 0;
		for(int j=1; j<=n; ++j) {
			for(int p=0; p<3; ++p) {
				if(field[p]==map[i][j]) temp[p]++;
				dp[p][i][j] = dp[p][i-1][j] + temp[p];
			}
		}
	}
	for(int q=0; q<k; ++q) {
		cin >> a >> b >> c >> d;
		for(int p=0; p<3; ++p) {
			ans = dp[p][c][d] - dp[p][c][b-1] - dp[p][a-1][d] + dp[p][a-1][b-1];
			cout << (!p?"":" ") << ans;
		}
		cout << endl;
	}
	return 0;
}