#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 1000, MAX_N = 1000;
const int MAX_K = 100000;
int m, n;
int k;
char field[MAX_M][MAX_N];
int j[MAX_K], o[MAX_K], i[MAX_K];
int main() {
  scanf("%d %d", &m, &n);
  scanf("%d", &k);
  for (int p = 0; p < m; p++) {
    scanf("%s", field[p]);
  }
  for (int p = 0; p < k; p++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    for (int y = a - 1; y < c; y++) {
      for (int x = b - 1; x < d; x++) {
        switch (field[y][x]) {
          case 'J':
            j[p]++;
            break;
          case 'O':
            o[p]++;
            break;
          case 'I':
            i[p]++;
            break;
        }
      }
    }
  }
  for (int p = 0; p < k; p++) {
    printf("%d %d %d\n", j[p], o[p], i[p]);
  }
  return 0;
}
