#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

struct joi{
	int j, o, i;
};

int main(){
	int r, c, n;
	cin >> r >> c >> n;
	
	string s[r+1];
	vector<vector<joi> > m(r+1, vector<joi>(c+1, (joi){0, 0, 0}));
	FOR(i, 1, r+1){
		cin >> s[i];
		FOR(j, 1, c+1){
			m[i][j]=m[i][j-1];
			if(s[i][j-1]=='J') m[i][j].j++;
			else if(s[i][j-1]=='O') m[i][j].o++;
			else if(s[i][j-1]=='I') m[i][j].i++;
		}
	}
	
	REP(i, n){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		
		int J, O, I=O=J=0;
		FOR(j, a, c+1){
			J+=(m[j][d].j-m[j][b-1].j);
			O+=(m[j][d].o-m[j][b-1].o);
			I+=(m[j][d].i-m[j][b-1].i);
		}
		
		cout << J << " " << O << " " << I << endl;
	}
}