#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int M,N,K;
  int a,b,c,d;
  cin>>M>>N>>K;
  vector< vector<char> >f(M+1,vector<char>(N+1,0));
  vector< vector<int> >J(M+1,vector<int>(N+1,0));
  vector< vector<int> >O(M+1,vector<int>(N+1,0));
  vector< vector<int> >I(M+1,vector<int>(N+1,0));

  for(int i=1;i<=M;i++){
    for(int j=1;j<=N;j++){
      cin>>f[i][j];
    }
  }

  for(int i=1;i<=M;i++){
    J[i][1] = (f[i][1]=='J');
    O[i][1] = (f[i][1]=='O');
    I[i][1] = (f[i][1]=='I');
    for(int j=2;j<=N;j++){
      J[i][j] = J[i][j-1] + (f[i][j]=='J');
      O[i][j] = O[i][j-1] + (f[i][j]=='O');
      I[i][j] = I[i][j-1] + (f[i][j]=='I');
    }
  }
  for(int i=2;i<=M;i++){
    for(int j=1;j<=N;j++){
      J[i][j]+=J[i-1][j];
      O[i][j]+=O[i-1][j];
      I[i][j]+=I[i-1][j];
    }
  }

  for(int i=0;i<K;i++){
    cin>>a>>b>>c>>d;
    cout<<J[c][d]-J[c][b-1]-J[a-1][d]+J[a-1][b-1]<<" "
	<<O[c][d]-O[c][b-1]-O[a-1][d]+O[a-1][b-1]<<" "
	<<I[c][d]-I[c][b-1]-I[a-1][d]+I[a-1][b-1]<<endl;
  }
}