#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> m >> n;
  string data[m];
  int k;
  cin >> 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];
    cin >> row[0] >> col[0] >> row[1] >> col[1];
    for (int r = row[0] - 1; r < row[1]; r++) {
      for (int c = col[0] - 1; c < col[1]; c++) {
        if (data[r][c] == 'J') sum[0]++;
        if (data[r][c] == 'O') sum[1]++;
        if (data[r][c] == 'I') sum[2]++;
      }
    }
    cout << sum[0] << " " << sum[1] << " " << sum[2] << endl;
  }
  return 0;
}
