#include <bits/stdc++.h>
int m, n, k, c[1005][1005][3];
char ma[1005][1005];
int f(int a) { return (a >= 0) ? a : 1004; }
int main() {
  scanf("%d%d%d ", &m, &n, &k);
  for (int(i) = 0; i < m; i++) {
    scanf(" %s ", ma[i]);
    for (int(j) = 0; j < n; j++) {
      if (ma[i][j] == 'J')
        c[i][j][0]++;
      else if (ma[i][j] == 'O')
        c[i][j][1]++;
      else
        c[i][j][2]++;
      for (int(x) = 0; x < 3; x++) c[i][j][x] += c[i][f(j - 1)][x];
    }
  }
  for (int(i) = 0; i < m; i++)
    for (int(j) = 0; j < n; j++)
      for (int(x) = 0; x < 3; x++) c[i][j][x] += c[f(i - 1)][j][x];
  int lx, ly, rx, ry;
  for (int(i) = 0; i < k; i++) {
    scanf("%d%d%d%d", &lx, &ly, &rx, &ry);
    lx--;
    ly--;
    rx--;
    ry--;
    for (int(x) = 0; x < 3; x++) {
      printf("%d", c[rx][ry][x] - c[f(lx - 1)][ry][x] - c[rx][f(ly - 1)][x] +
                       c[f(lx - 1)][f(ly - 1)][x]);
      if (x < 2) printf(" ");
    }
    if (i < (k - 1)) printf("\n");
  }
  return 0;
}
