#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  scanf("%d %d", &m, &n);
  string data[m];
  int k;
  scanf("%d", &k);
  string trash;
  getline(cin, trash);
  for (int i = 0; i < m; i++) {
    getline(cin, data[i]);
  }
  for (int i = 0; i < k; i++) {
    int sum[3] = {0, 0, 0};
    int row[2], col[2];
    scanf("%d %d %d %d", &row[0], &col[0], &row[1], &col[1]);
    if (!((col[0] - col[1]) % 2)) {
      for (int r = row[0] - 1; r < row[1]; r++) {
        for (int c = col[0] - 1; c < col[1]; c++) {
          if (data[r][c] == 'J') sum[0]++;
          if (data[r][c] == 'O') sum[1]++;
          if (data[r][c] == 'I') sum[2]++;
        }
      }
    } else {
      for (int r = row[0] - 1; r < row[1]; r++) {
        for (int c = col[0] - 1; c < col[1]; c += 2) {
          if (data[r][c] == 'J' || data[r][c + 1] == 'J') sum[0]++;
          if (data[r][c] == 'O' || data[r][c + 1] == 'O') sum[1]++;
          if (data[r][c] == 'I' || data[r][c + 1] == 'I') sum[2]++;
        }
      }
    }
    printf("%d %d %d\n", sum[0], sum[1], sum[2]);
  }
  return 0;
}
