#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 1010
using namespace std;

int m,n,k,J[MAX][MAX],O[MAX][MAX],I[MAX][MAX];
string s[MAX];

void solve(){
 cin>>n>>m;
 cin>>k;
 ZERO(J); ZERO(O); ZERO(I);
 FOR(i,n) cin>>s[i];
 FOR(i,n){
  FOR(j,m){
   int jj=0,oo=0,ii=0;
   if(s[i][j]=='J') jj=1;
   else if(s[i][j]=='O') oo=1;
   else ii=1;
   J[i+1][j+1]=jj+J[i][j+1]+J[i+1][j]-J[i][j];
   O[i+1][j+1]=oo+O[i][j+1]+O[i+1][j]-O[i][j];
   I[i+1][j+1]=ii+I[i][j+1]+I[i+1][j]-I[i][j];
  }
 }
 int a,b,c,d;
 FOR(i,k){
  cin>>a>>b>>c>>d;
  a--; b--;
  int jj=J[c][d]-J[c][b]-J[a][d]+J[a][b];
  int oo=O[c][d]-O[c][b]-O[a][d]+O[a][b];
  int ii=I[c][d]-I[c][b]-I[a][d]+I[a][b];
  cout<<jj<<" "<<oo<<" "<<ii<<endl;
 }
}

int main(){
 solve();
 return 0;
}