#include <bits/stdc++.h>
int main() {
  int m, n, i, j, k;
  long int K;
  int a, b, c, d;
  char tmp;
  int I[124][124] = {0}, O[124][124] = {0}, J[124][124] = {0};
  int tmp1;
  scanf("%d %d\n%ld\n", &m, &n, &K);
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%c", &tmp);
      if (tmp == '\n') scanf("%c", &tmp);
      if (i == 1 && j == 1) {
      } else if (i == 1) {
        J[i][j] = J[i][j - 1];
        O[i][j] = O[i][j - 1];
        I[i][j] = I[i][j - 1];
      } else if (j == 1) {
        J[i][j] = J[i - 1][j];
        O[i][j] = O[i - 1][1];
        I[i][j] = I[i - 1][1];
      } else {
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];
      }
      if (tmp == 'J') {
        J[i][j] += 1;
      } else if (tmp == 'O') {
        O[i][j] += 1;
      } else if (tmp == 'I') {
        I[i][j] += 1;
      }
    }
  }
  printf("%c", &tmp);
  for (i = 0; i < K; i++) {
    scanf("%d %d %d %d\n", &a, &b, &c, &d);
    tmp1 = J[c][d] - J[c][b - 1] - J[a - 1][d] + J[a - 1][b - 1];
    printf("%d ", tmp1);
    tmp1 = O[c][d] - O[c][b - 1] - O[a - 1][d] + O[a - 1][b - 1];
    printf("%d ", tmp1);
    tmp1 = I[c][d] - I[c][b - 1] - I[a - 1][d] + I[a - 1][b - 1];
    printf("%d\n", tmp1);
  }
  return 0;
}
