#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int M, N, K;
  char res[1000][1000];
  int xp, yp, xq, yq;
  int J, O, I;
  cin >> M >> N;
  cin >> K;
  for (int i = 0; i < M; i++) {
    scanf("%s", res[i]);
  }
  while (cin >> xp >> yp >> xq >> yq) {
    J = 0;
    O = 0;
    I = 0;
    for (int j = yp - 1; j < yq; j++) {
      for (int i = xp - 1; i < xq; i++) {
        if (res[i][j] == 'J')
          J++;
        else if (res[i][j] == 'O')
          O++;
        else if (res[i][j] == 'I')
          I++;
      }
    }
    printf("%d %d %d\n", J, O, I);
  }
  return 0;
}
