#include <bits/stdc++.h>
using namespace std;
struct joi_t {
  int j, o, i;
  joi_t(int j = 0, int o = 0, int i = 0) : j(j), o(o), i(i) {}
  joi_t operator+(const joi_t &a) const {
    return joi_t(j + a.j, o + a.o, i + a.i);
  }
};
int M, N, K;
char planet[1000][1000];
joi_t seg[1000][1000 / 2];
joi_t count_joi(int y, int sx, int gx) {
  joi_t cnt;
  if (gx - sx < 2) {
    for (int i = sx; i <= gx; i++) {
      switch (planet[y][i]) {
        case 'J':
          cnt.j++;
          break;
        case 'O':
          cnt.o++;
          break;
        case 'I':
          cnt.i++;
          break;
      }
    }
  } else {
    int seg_s = (sx + 2 - 1) / 2;
    int seg_g = (gx - 2 + 1) / 2;
    for (int i = sx; i < seg_s * 2; i++) {
      switch (planet[y][i]) {
        case 'J':
          cnt.j++;
          break;
        case 'O':
          cnt.o++;
          break;
        case 'I':
          cnt.i++;
          break;
      }
    }
    for (int i = (seg_g + 1) * 2; i <= gx; i++) {
      switch (planet[y][i]) {
        case 'J':
          cnt.j++;
          break;
        case 'O':
          cnt.o++;
          break;
        case 'I':
          cnt.i++;
          break;
      }
    }
    for (int i = seg_s; i <= seg_g; i++) {
      cnt = cnt + seg[y][i];
    }
  }
  return cnt;
}
int main() {
  cin >> M >> N >> K;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < N; j++) cin >> planet[i][j];
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 1000 / 2; j++) {
      for (int k = j * 2; k < (j + 1) * 2; k++) {
        switch (planet[i][k]) {
          case 'J':
            seg[i][j].j++;
            break;
          case 'O':
            seg[i][j].o++;
            break;
          case 'I':
            seg[i][j].i++;
            break;
        }
      }
    }
  }
  for (int i = 0; i < K; i++) {
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--, sx--, gy--, gx--;
    joi_t cnt;
    for (int j = sy; j <= gy; j++) {
      cnt = cnt + count_joi(j, sx, gx);
    }
    cout << cnt.j << ' ' << cnt.o << ' ' << cnt.i << endl;
  }
  return 0;
}
