#include <bits/stdc++.h>
using namespace std;
char s[1001][1001];
int main() {
  int n, m, k, a, b, c, d, J, O, I;
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < (m); i++) scanf("%s", s[i]);
  for (int i = 0; i < (k); i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--;
    b--;
    c--;
    d--;
    J = O = I = 0;
    for (int i = a; i <= c; i++)
      for (int j = b; j <= d; j++) {
        if (s[i][j] == 'J')
          J++;
        else if (s[i][j] == 'O')
          O++;
        else if (s[i][j] == 'I')
          I++;
      }
    printf("%d %d %d\n", J, O, I);
  }
  return 0;
}
