#include <bits/stdc++.h>
using namespace std;
int jungle[1280][1280];
int ocean[1280][1280];
int ice[1280][1280];
int main(void) {
  int m, n, cnt;
  string str;
  cin >> m >> n >> cnt;
  for (int i = 0; i < m; i++) {
    cin >> str;
    for (int j = 0; j < n; j++) {
      if (str[j] == 'J') jungle[i + 1][j + 1] = 1;
      if (str[j] == 'O') ocean[i + 1][j + 1] = 1;
      if (str[j] == 'I') ice[i + 1][j + 1] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      jungle[i][j] += jungle[i][j - 1];
      ocean[i][j] += ocean[i][j - 1];
      ice[i][j] += ice[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      jungle[j][i] += jungle[j - 1][i];
      ocean[j][i] += ocean[j - 1][i];
      ice[j][i] += ice[j - 1][i];
    }
  }
  int a, b, c, d;
  while (cnt--) {
    cin >> a >> b >> c >> d;
    swap(a, b);
    swap(c, d);
    int j = jungle[d][c] - jungle[b - 1][c] - jungle[d][a - 1] +
            jungle[b - 1][a - 1];
    int o =
        ocean[d][c] - ocean[b - 1][c] - ocean[d][a - 1] + ocean[b - 1][a - 1];
    int i = ice[d][c] - ice[b - 1][c] - ice[d][a - 1] + ice[b - 1][a - 1];
    printf("%d %d %d\n", j, o, i);
  }
  return 0;
}
