#include <iostream>
#include <cstdio>
using namespace std;

int main(){
  int h,w,k;
  static int cnt[1000][1000][3] = {};
  char field[1000][1000],joi[] = {'J','O','I'};
  cin >> h >> w >> k;
  getchar();
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      field[i][j] = getchar();
    }
    getchar();
  }
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      for(int l = 0;l < 3;l++){
	if(i == 0 && j != 0){
	  cnt[i][j][l] = cnt[i][j - 1][l];
	}
	else if(j == 0 && i != 0){
	  cnt[i][j][l] = cnt[i - 1][j][l];
	}
	else if(j != 0 && i != 0){
	  cnt[i][j][l] = cnt[i - 1][j][l] + cnt[i][j - 1][l] - cnt[i - 1][j - 1][l];
	}
        if(field[i][j] == joi[l]) cnt[i][j][l]++;
      }
    }
  }
  for(int i = 0;i < k;i++){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;b--;c--;d--;
    int joicnt[3] = {};
    for(int j = 0;j < 3;j++){
      if(a == 0 && b == 0) joicnt[j] = cnt[c][d][j];
      else if(a == 0) joicnt[j] = cnt[c][d][j] - cnt[c][b - 1][j];
      else if(b == 0) joicnt[j] = cnt[c][d][j] - cnt[a - 1][d][j];
      else joicnt[j] = cnt[c][d][j] - cnt[a - 1][d][j] - cnt[c][b - 1][j] + cnt[a - 1][b - 1][j];
    }
    cout << joicnt[0] << " " << joicnt[1] << " " << joicnt[2] << endl;
  }
  return 0;
}