#include <bits/stdc++.h>
int m, n, k;
int a, b, c, d;
char area[1000][1001];
void count_area(int top, int left, int bottom, int right, int *j_, int *o_,
                int *i_) {
  int i, j;
  char c;
  *j_ = *o_ = *i_ = 0;
  for (i = top; i <= bottom; i++)
    for (j = left; j <= right; j++) {
      c = area[i][j];
      if (c == 'J')
        (*j_)++;
      else if (c == 'O')
        (*o_)++;
      else if (c == 'I')
        (*i_)++;
    }
}
int main() {
  int i, j;
  int jcount, ocount, icount;
  scanf("%d %d", &m, &n);
  scanf("%d", &k);
  for (i = 0; i < m; i++) scanf("%s", &area[i][0]);
  for (i = 0; i < k; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    count_area(a - 1, b - 1, c - 1, d - 1, &jcount, &ocount, &icount);
    printf("%d %d %d\n", jcount, ocount, icount);
  }
  return (0);
}
