#include<iostream>
#include<algorithm>
using namespace std;
char fie[1002][1002];
int J[1002][1002];
int O[1002][1002];
int I[1002][1002];
int main(){
  int n,m,k;
  int i;

  cin >> n >> m;
  cin >> k;
  for(int i=0;i<n;i++){
      cin >> fie[i];
  }

  for(int j=0;j<m;j++){
    int Jc=0;
    int Oc=0;
    int Ic=0;
    for(int i=0;i<n;i++){
      if(fie[i][j]=='J') Jc++;
      else if(fie[i][j]=='O') Oc++;
      else if(fie[i][j]=='I') Ic++;
      J[i][j]=Jc;
      O[i][j]=Oc;
      I[i][j]=Ic;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=1;j<m;j++){
      J[i][j]+=J[i][j-1];
      O[i][j]+=O[i][j-1];
      I[i][j]+=I[i][j-1];
    }
  }

  /* for(int i=0;i<n;i++){
    for(int j=0;j<m;j++) cout << J[i][j];
    cout << endl;
    }*/

  for(int i=0;i<k;i++){
    int x1,x2,y1,y2;
    cin >> y1 >> x1 >> y2 >> x2;
    x1--;
    y1--;
    x2--;
    y2--;
    cout << J[y2][x2]-J[y2][x1-1]-J[y1-1][x2]+J[y1-1][x1-1] << ' ';
    cout << O[y2][x2]-O[y2][x1-1]-O[y1-1][x2]+O[y1-1][x1-1] << ' ';
    cout << I[y2][x2]-I[y2][x1-1]-I[y1-1][x2]+I[y1-1][x1-1] << endl;
  }
  
  return 0;
}