#include <bits/stdc++.h>
using namespace std;
int main() {
  const int MAX_N = 1000;
  int J[MAX_N + 1][MAX_N + 1];
  int O[MAX_N + 1][MAX_N + 1];
  int I[MAX_N + 1][MAX_N + 1];
  char input[MAX_N + 10][MAX_N + 10];
  int N, M, K;
  int plus_j, plus_o, plus_i;
  int a, b, c, d;
  int res_j, res_o, res_i;
  scanf("%d%d", &M, &N);
  scanf("%d", &K);
  for (int i = 0; i < M; i++) scanf("%s", input[i]);
  for (int i = 0; i <= M; i++) {
    for (int j = 0; j <= N; j++) {
      if (i == 0 || j == 0) {
        J[i][j] = 0;
        O[i][j] = 0;
        I[i][j] = 0;
      } else {
        plus_j = 0;
        plus_o = 0;
        plus_i = 0;
        if (input[i - 1][j - 1] == 'J')
          plus_j = 1;
        else if (input[i - 1][j - 1] == 'O')
          plus_o = 1;
        else if (input[i - 1][j - 1] == 'I')
          plus_i = 1;
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1] + plus_j;
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1] + plus_o;
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1] + plus_i;
      }
    }
  }
  for (int i = 0; i < K; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    res_j = J[c][d] - (J[a - 1][d] + J[c][b - 1] - J[a - 1][b - 1]);
    res_o = O[c][d] - (O[a - 1][d] + O[c][b - 1] - O[a - 1][b - 1]);
    res_i = I[c][d] - (I[a - 1][d] + I[c][b - 1] - I[a - 1][b - 1]);
    printf("%d %d %d\n", res_j, res_o, res_i);
  }
  return 0;
}
