#include <bits/stdc++.h>
int num[3][1001][1001];
int main() {
  int m, n, k;
  int i, j, l;
  scanf("%d %d %d", &m, &n, &k);
  for (i = 0; i <= m; i++)
    for (j = 0; j <= n; j++)
      for (l = 0; l < 3; l++) num[l][i][j] = 0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      char c;
      scanf(" %c", &c);
      if (c == 'J') num[0][i][j] = 1;
      if (c == 'O') num[1][i][j] = 1;
      if (c == 'I') num[2][i][j] = 1;
    }
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      for (l = 0; l < 3; l++) num[l][i][j] += num[l][i][j - 1];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      for (l = 0; l < 3; l++) num[l][j][i] += num[l][j - 1][i];
    }
  }
  for (i = 0; i < k; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    for (j = 0; j < 3; j++) {
      int ans = num[j][x2][y2] - num[j][x2][y1 - 1] - num[j][x1 - 1][y2] +
                num[j][x1 - 1][y1 - 1];
      printf("%d ", ans);
    }
    puts("");
  }
}
