#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int m, n,kk;
	cin >> m >> n>>kk;
	vector<vector<int> > t(m, vector<int>(n));
	string s = "JOI";
	for (int i = 0; i < m; i++) {
		string u;
		cin >> u;
		for (int j = 0; j < n; j++) {
			char x = u[j];
			for (int k = 0; k < 3; k++) {
				if (x == s[k]) {
					t[i][j] = k;
				}
			}
		}
	}
	vector<vector<vector<int> > > joi(m+1, vector<vector<int> >(n+1,vector<int>(3,0)));
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 0; k < 3; k++) {
				joi[i][j][k] = joi[i - 1][j][k] + joi[i][j - 1][k] - joi[i - 1][j - 1][k];
			}
			joi[i][j][t[i-1][j-1]]++;
		}
	}
	vector<vector<int> > ans(kk,vector<int> (3));
	for (int i = 0; i < kk; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		for (int k = 0; k < 3; k++) {
		    ans[i][k]=joi[c][d][k] - joi[c][b - 1][k] - joi[a - 1][d][k] + joi[a - 1][b - 1][k];
		}
	}
	for(int i=0;i<kk;i++){
	    for(int j=0;j<3;j++){
	        cout << ans[i][j];
	        if(j<2){
	            cout << " ";
	        }
	    }
	    cout << endl;
	}
}
