#include<iostream>
using namespace std;

int n,m,k;
int j[1100][1100],o[1100][1100],i[1100][1100];
int tj,to,ti;
string tmp;
int a,b,c,d;

int main(){
  cin >> m >> n >> k;

  for(int y=0;y<m;y++){
    tj = to = ti = 0;
    cin >> tmp;
    j[y][0] = o[y][0] = i[y][0] = 0;
    for(int x=0;x<n;x++){
      if(tmp[x] == 'J')tj++;
      if(tmp[x] == 'O')to++;
      if(tmp[x] == 'I')ti++;
      j[y][x+1] = tj;
      o[y][x+1] = to;
      i[y][x+1] = ti;
    }
  }
 
  while(k--){
    cin >> a >> b >> c >> d;
    tj = to = ti = 0;
    for(int y=a-1;y<c;y++){
      tj += j[y][d] - j[y][b-1];
      to += o[y][d] - o[y][b-1]; 
      ti += i[y][d] - i[y][b-1];
    }
    cout << tj << " " << to << " " <<  ti << endl;
  }
}