#include <bits/stdc++.h>
int main(void) {
  int M, N, K;
  scanf("%d %d %d", &M, &N, &K);
  char po[1919][1919];
  for (int i = 0; i < M; i++) {
    scanf("%s", po[i]);
  }
  int buri[3][1919][1919] = {};
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (po[i][j] == 'J') buri[0][i + 1][j + 1] = 1;
      if (po[i][j] == 'O') buri[1][i + 1][j + 1] = 1;
      if (po[i][j] == 'I') buri[2][i + 1][j + 1] = 1;
    }
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 1919; j++)
      for (int k = 0; k < 1910; k++) {
        buri[i][j][k + 1] += buri[i][j][k];
      }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 1910; j++)
      for (int k = 0; k < 1919; k++) buri[i][j + 1][k] += buri[i][j][k];
  for (int i = 0; i < K; i++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    for (int j = 0; j < 3; j++) {
      printf("%d", buri[j][c][d] - buri[j][c][b - 1] - buri[j][a - 1][d] +
                       buri[j][a - 1][c - 1]);
      if (j != 2)
        printf(" ");
      else
        printf("\n");
    }
  }
  return 0;
}
