#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef long long ll;

int M, N, K;
char field[1000][1000];
int J[1000][1000], O[1000][1000], I[1000][1000];
int a, b, c, d;

signed main()
{
	cin >> M >> N >> K;
	rep(i,M) cin >> field[i];

	rep(i,M) {
		int JSum = 0, OSum = 0, ISum = 0;
		rep(j,N) {
			if (field[i][j] == 'J') JSum++;
			else if (field[i][j] == 'O') OSum++;
			else if (field[i][j] == 'I') ISum++;

			if (i == 0) {
				J[i][j] = JSum;
				O[i][j] = OSum;
				I[i][j] = ISum;
			} else {
				J[i][j] = J[i-1][j] + JSum;
				O[i][j] = O[i-1][j] + OSum;
				I[i][j] = I[i-1][j] + ISum;
			}
		}
	}

	/*
	rep(i,M) {		
		rep(j,N) {
			printf("%d ", O[i][j]);
		}
		cout << endl;
	}
	*/

	rep(i,K) {
		cin >> a >> b >> c >> d;
		--a; --b; --c; --d;
		int ansJ = J[c][d]; int ansO = O[c][d]; int ansI = I[c][d];
		if (a >= 1) {
			ansJ -= J[a-1][d]; ansO -= O[a-1][d]; ansI -= I[a-1][d];
		}
		if (b >= 1) {
			ansJ -= J[c][b-1]; ansO -= O[c][b-1]; ansI -= I[c][b-1];
		}
		if (a >= 1 && b >= 1) {
			ansJ += J[a-1][b-1]; ansO += O[a-1][b-1]; ansI += I[a-1][b-1];
		}

		cout << ansJ << " " << ansO << " " << ansI << endl;
	}
}