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