#include <iostream>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <map>
#include <cmath>
#include <string>
//#include <sstream>
#include <iomanip>
//#include <complex>
//小数制度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back


	int map_j[1010][1010];
	int map_o[1010][1010];
	int map_i[1010][1010];

int main(){
	int h,w;
	ll int kk;
	cin >> h >> w;
	cin >> kk;
	string st;
	vector < string > joi;
	REP(i,h){
		cin >> str;
		joi.pb(st);
	}

	string hit = "JOI";

	int tmp = 0;
	
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[0]) tmp++;
			map_j[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+2){
				if(joi[j-1][k-1]==hit[0]) tmp++;
				map_j[j][k] = map_j[j-1][k]+tmp;
			}
		}
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[1]) tmp++;
			map_o[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+1){
				if(joi[j-1][k-1]==hit[1]) tmp++;
				map_o[j][k] = map_o[j-1][k]+tmp;
			}
		}
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[2]) tmp++;
			map_i[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+2){
				if(joi[j-1][k-1]==hit[2]) tmp++;
				map_i[j][k] = map_i[j-1][k]+tmp;
			}
		}	

	REP(i,kk){
		int x1,y1,x2,y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int t[3];
			t[0] = map_j[x2][y2]+map_j[x1-1][y1-1]-map_j[x1-1][y2]-map_j[x2][y1-1];
			t[1] = map_o[x2][y2]+map_o[x1-1][y1-1]-map_o[x1-1][y2]-map_o[x2][y1-1];
			t[2] = map_i[x2][y2]+map_i[x1-1][y1-1]-map_i[x1-1][y2]-map_i[x2][y1-1];
		
		cout << t[0] << " " << t[1] << " " << t[2]<<endl;
 	}
 	return 0;


}