#include <bits/stdc++.h>
using namespace std;
char JOI[1005][1005];
int jangle, ocean, ice;
void search(int a, int b, int c, int d, int sum) {
  int i = 0, j = 0, k = 0, cnt = 0;
  int x, y;
  y = a;
  x = b;
  while (cnt < sum) {
    if (JOI[y][x] == 'J')
      i++;
    else if (JOI[y][x] == 'O')
      j++;
    else if (JOI[y][x] == 'I')
      k++;
    if (x == d) {
      y++;
      x = b;
    } else
      x++;
    cnt++;
  }
  jangle = i;
  ocean = j;
  ice = k;
}
int main() {
  int m, n;
  cin >> m >> n;
  int k;
  cin >> k;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) cin >> JOI[i][j];
  int a, b, c, d;
  for (int i = 0; i < k; i++) {
    cin >> a >> b >> c >> d;
    int sum = 0;
    sum = (c - a + 1) * (d - b + 1);
    search(a, b, c, d, sum);
    cout << jangle << " " << ocean << " " << ice;
    cout << endl;
  }
}
