#include <bits/stdc++.h>
int J[1001][1001], O[1001][1001], I[1001][1001];
int a[100001], b[100001], c[100001], d[100001];
char joi[1001][1001];
int main(void) {
  int M, N, K, i, j, sumJ, sumO, sumI;
  scanf("%d%d%d", &M, &N, &K);
  for (i = 1; i <= M; i++) {
    for (j = 1; j <= N; j++) {
      scanf(" %c", &joi[i][j]);
    }
  }
  for (i = 1; i <= K; i++) {
    scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
  }
  for (i = 1; i <= M; i++) {
    for (j = 1; j <= N; j++) {
      J[i][j] = 0;
      O[i][j] = 0;
      I[i][j] = 0;
    }
  }
  for (i = 1; i <= M; i++) {
    for (j = 1; j <= N; j++) {
      if (joi[i][j] == 'J') {
        J[i][j]++;
      }
      if (joi[i][j] == 'O') {
        O[i][j]++;
      }
      if (joi[i][j] == 'I') {
        I[i][j]++;
      }
      J[i][j + 1] += J[i][j];
      O[i][j + 1] += O[i][j];
      I[i][j + 1] += I[i][j];
    }
  }
  for (i = 1; i <= K; i++) {
    sumJ = 0;
    for (j = 1; j <= c[i]; j++) {
      sumJ += J[j][d[i]];
    }
    for (j = 1; j < a[i]; j++) {
      sumJ -= J[j][d[i]];
    }
    for (j = 1; j <= c[i]; j++) {
      sumJ -= J[j][b[i] - 1];
    }
    for (j = 1; j < a[i]; j++) {
      sumJ += J[j][b[i] - 1];
    }
    printf("%d ", sumJ);
    sumO = 0;
    for (j = 1; j <= c[i]; j++) {
      sumO += O[j][d[i]];
    }
    for (j = 1; j < a[i]; j++) {
      sumO -= O[j][d[i]];
    }
    for (j = 1; j <= c[i]; j++) {
      sumO -= O[j][b[i] - 1];
    }
    for (j = 1; j < a[i]; j++) {
      sumO += O[j][b[i] - 1];
    }
    printf("%d ", sumO);
    sumI = 0;
    for (j = 1; j <= c[i]; j++) {
      sumI += I[j][d[i]];
    }
    for (j = 1; j < a[i]; j++) {
      sumI -= I[j][d[i]];
    }
    for (j = 1; j <= c[i]; j++) {
      sumI -= I[j][b[i] - 1];
    }
    for (j = 1; j < a[i]; j++) {
      sumI += I[j][b[i] - 1];
    }
    printf("%d\n", sumI);
  }
  return 0;
}
