#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

class Land { 
public:
	int J, O, I;
	Land(int j = 0, int o = 0, int i = 0) {
		J = j;
		O = o;
		I = i;
	}
	Land operator + (Land other) {
		Land res(0, 0, 0);
		res.J = J + other.J;
		res.O = O + other.O;
		res.I = I + other.I;
		return res;
	}
};

int main() {
	int w, h, k, i, j;
	cin >> h >> w >> k;
	vs a(h);
	for (i = 0; i < h; i++) {
		cin >> a[i];
	}
	Land z();
	vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j];
			switch (a[i][j]) {
			case 'J':
				sum[i + 1][j + 1].J++;
				break;
			case'O':
				sum[i + 1][j + 1].O++;
				break;
			default:
				sum[i + 1][j + 1].I++;
			}
		}
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j + 1] + sum[i][j + 1];
		}
	}
	/*
	for (i = 0; i <= h; i++) {
		for (j = 0; j <= w; j++) {
			cout << sum[i][j].J << sum[i][j].O << sum[i][j].I << " ";
		}
		cout << endl;
	}
	*/
	for (i = 0; i < k; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int J = 0, O = 0, I = 0;
		J = sum[c][d].J - sum[c][b - 1].J - sum[a - 1][d].J + sum[a - 1][b - 1].J;
		O = sum[c][d].O - sum[c][b - 1].O - sum[a - 1][d].O + sum[a - 1][b - 1].O;
		I = sum[c][d].I - sum[c][b - 1].I - sum[a - 1][d].I + sum[a - 1][b - 1].I;
		cout << J << " " << O << " " << I << endl;
	}
}