#include <bits/stdc++.h>
int M, N, K;
int main() {
  scanf("%d%d%d", &M, &N, &K);
  int field[M + 1][N + 1][3];
  for (int i = 0; i <= M; i++) {
    for (int j = 0; j < 3; j++) {
      field[i][0][j] = 0;
    }
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < 3; j++) {
      field[0][i][j] = 0;
    }
  }
  char aaaaaaaaaaaaaaaaaaaaa;
  scanf("%c", &aaaaaaaaaaaaaaaaaaaaa);
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      char in;
      scanf("%c", &in);
      for (int k = 0; k < 3; k++) {
        field[i][j][k] =
            field[i - 1][j][k] + field[i][j - 1][k] - field[i - 1][j - 1][k];
      }
      if (in == 'J') {
        field[i][j][0]++;
      } else if (in == 'O') {
        field[i][j][1]++;
      } else {
        field[i][j][2]++;
      }
    }
    char in;
    scanf("%c", &in);
  }
  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++) {
      int ret = field[c][d][j] - field[c][b - 1][j] - field[a - 1][d][j] +
                field[a - 1][b - 1][j];
      printf("%d", ret);
      if (j != 2) {
        printf(" ");
      }
    }
    if (i != K - 1) {
      printf("\n");
    }
  }
  return 0;
}
