#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 a[1010][1010];
int b[1010][1010];
char s[1010];
int main() {
  scanf("%d%d%d", &M, &N, &K);
  for (int i = 1; i <= M; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= N; j++) {
      if (s[j] == 'J') {
        a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + 1;
        b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
      } else if (board[i][j] == 'O') {
        a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + 1;
      } else {
        a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
      }
    }
  }
  int s, t, u, v;
  for (int l = 0; l < K; l++) {
    int ansJ, ansO, ansI;
    scanf("%d%d%d%d", &s, &t, &u, &v);
    s--;
    t--;
    ansJ = a[u][v] - a[s][v] - a[u][t] + a[s][t];
    ansO = b[u][v] - b[s][v] - b[u][t] + b[s][t];
    ansI = (u - s) * (v - t) - (ansJ + ansO);
    printf("%d %d %d\n", ansJ, ansO, ansI);
  }
  return 0;
}
