#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N, K, a, b, c, d, ans[5];
  string input;
  vector<vector<vector<int> > > sum;
  vector<vector<int> > po;
  vector<int> z;
  for (int l = 0; l < 3; l++) z.push_back(0);
  cin >> M >> N >> K;
  for (int j = 0; j < M + 1; j++) {
    for (int k = 0; k < N + 1; k++) {
      po.push_back(z);
    }
    sum.push_back(po);
  }
  for (int j = 1; j <= M; j++) {
    cin >> input;
    for (int k = 1; k <= N; k++) {
      if (input[k - 1] == 'J') sum[j][k][0] = 1;
      if (input[k - 1] == 'O') sum[j][k][1] = 1;
      if (input[k - 1] == 'I') sum[j][k][2] = 1;
    }
  }
  for (int j = 1; j <= M; j++) {
    for (int k = 1; k <= N; k++) {
      for (int l = 0; l < 3; l++) {
        sum[j][k][l] += sum[j][k - 1][l];
      }
    }
  }
  for (int k = 1; k <= N; k++) {
    for (int j = 1; j <= M; j++) {
      for (int l = 0; l < 3; l++) {
        sum[j][k][l] += sum[j - 1][k][l];
      }
    }
  }
  for (int i = 0; i < K; i++) {
    cin >> a >> b >> c >> d;
    for (int l = 0; l < 3; l++)
      ans[l] = sum[a - 1][b - 1][l] + sum[c][d][l] - sum[a - 1][d][l] -
               sum[c][b - 1][l];
    printf("%d %d %d\n", ans[0], ans[1], ans[2]);
  }
  return 0;
}
