#include <bits/stdc++.h>
using namespace std;
template <typename T>
void FILL_(void* ptr, size_t size, T value) {
  std::fill((T*)ptr, (T*)ptr + size, value);
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int M, N, K;
const int MAX_M = 1010;
const int MAX_N = 1010;
char board[MAX_M][MAX_N];
char c;
int main() {
  scanf("%d %d", &M, &N);
  scanf("%d", &K);
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> c;
      board[i][j] = c;
    }
  }
  int a, b, c, d;
  for (int l = 0; l < K; l++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int ansJ = 0;
    int ansO = 0;
    int ansI = 0;
    for (int i = a; i <= c; i++) {
      for (int j = b; j <= d; j++) {
        if (board[i][j] == 'J')
          ansJ++;
        else if (board[i][j] == 'O')
          ansO++;
        else if (board[i][j] == 'I')
          ansI++;
      }
    }
    printf("%d %d %d\n", ansJ, ansO, ansI);
  }
  return 0;
}
