#include <bits/stdc++.h>
int M, N;
int K;
char map[1003];
int ***data;
int look[4];
void seach(int *ans) {
  int i;
  for (i = 0; i < 3; i++) {
    ans[i] = data[look[2]][look[3]][i] - data[look[2]][look[1] - 1][i];
    ans[i] +=
        -data[look[0] - 1][look[3]][i] + data[look[0] - 1][look[1] - 1][i];
  }
}
int main() {
  int i, j, k;
  int ans[3];
  int J = 0, O = 0, I = 0;
  scanf("%d%d%d", &M, &N, &K);
  data = new int **[M + 1];
  for (i = 0; i < M + 1; i++) {
    data[i] = new int *[N + 1];
    for (j = 0; j < N + 1; j++) {
      data[i][j] = new int[3];
      for (k = 0; k < 3; k++) {
        data[i][j][k] = 0;
      }
    }
  }
  for (i = 1; i < M + 1; i++) {
    scanf("%s", map + 1);
    for (j = 1; j < N + 1; j++) {
      switch (map[j]) {
        case 'J':
          J++;
          break;
        case 'O':
          O++;
          break;
        case 'I':
          I++;
          break;
      }
      data[i][j][0] = J - data[i - 1][N][0] + data[i - 1][j][0];
      data[i][j][1] = O - data[i - 1][N][1] + data[i - 1][j][1];
      data[i][j][2] = I - data[i - 1][N][2] + data[i - 1][j][2];
    }
  }
  for (i = 0; i < K; i++) {
    for (j = 0; j < 4; j++) {
      scanf("%d", look + j);
    }
    seach(ans);
    for (j = 0; j < 3; j++) {
      printf("%d ", ans[j]);
    }
    printf("\n");
  }
  for (i = 0; i < M + 1; i++) {
    for (j = 0; j < N + 1; j++) {
      delete[] data[i][j];
    }
    delete[] data[i];
  }
  delete[] data;
  return 0;
}
