#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  scanf("%d %d", &m, &n);
  string data[m];
  int k;
  scanf("%d", &k);
  string trash;
  getline(cin, trash);
  for (int i = 0; i < m; i++) {
    getline(cin, data[i]);
  }
  for (int i = 0; i < k; i++) {
    int sum[3] = {0, 0, 0};
    int row[2], col[2];
    scanf("%d %d %d %d", &row[0], &col[0], &row[1], &col[1]);
    for (int r = row[0] - 1; r < row[1]; r++) {
      string sub = data[r].substr(col[0] - 1, col[1] - col[0] + 1);
      sort(sub.begin(), sub.end());
      int x = 0;
      while (sub[x] == 'I') {
        sum[2]++;
        x++;
      }
      while (sub[x] == 'J') {
        sum[0]++;
        x++;
      }
      sum[1] += sub.length() - x;
    }
    printf("%d %d %d\n", sum[0], sum[1], sum[2]);
  }
  return 0;
}
