#include <iostream>
using namespace std;

int dp[1001][1001][3];
int M, N, K;
int a, b, c, d;

int solve(int a, int b, int c, int d, int t){
  int ret = 0;
  for(int i = a; i <= c; i++){
    ret += dp[i][d][t] - dp[i][b-1][t];
  }
  return ret;
}

int main(void){
  cin >> M >> N;
  cin >> K;
  for(int i = 1; i <= M; i++){
    for(int j = 1; j <= N; j++){
      char c;
      cin >> c;
      if(c == 'J') dp[i][j][0]++;
      if(c == 'O') dp[i][j][1]++;
      if(c == 'I') dp[i][j][2]++;
      for(int k = 0; k < 3; k++){
        dp[i][j][k] += dp[i][j-1][k];
      }
    }
  }

  for(int k = 0; k < K; k++){
    int j, o, i;
    cin >> a >> b >> c >> d;
    j = solve(a, b, c, d, 0);
    o = solve(a, b, c, d, 1);
    i = solve(a, b, c, d, 2);
    cout << j << " " << o << " " << i << endl;
  }
  return 0;
}