#include <bits/stdc++.h>
using namespace std;
char JOI[1005][1005];
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++) {
    int jangle = 0, ocean = 0, ice = 0;
    cin >> a >> b >> c >> d;
    int half;
    half = (a + c) / 2 + 1;
    for (int h = a; h < half; h++) {
      for (int w = b; w <= d; w++) {
        if (JOI[h][w] == 'J')
          jangle++;
        else if (JOI[h][w] == 'O')
          ocean++;
        else if (JOI[h][w] == 'I')
          ice++;
      }
    }
    for (int h = half; h <= c; h++) {
      for (int w = b; w <= d; w++) {
        if (JOI[h][w] == 'J')
          jangle++;
        else if (JOI[h][w] == 'O')
          ocean++;
        else if (JOI[h][w] == 'I')
          ice++;
      }
    }
    cout << jangle << " " << ocean << " " << ice;
    cout << endl;
  }
}
