#include <bits/stdc++.h>
using namespace std;
int m, n, k;
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];
int main() {
  cin >> m >> n >> k;
  for (int i = 0; i <= m; i++) {
    J[0][i] = 0;
    O[0][i] = 0;
    I[0][i] = 0;
  }
  for (int i = 0; i <= n; i++) {
    J[i][0] = 0;
    O[i][0] = 0;
    I[i][0] = 0;
  }
  for (int y = 1; y <= m; y++) {
    int j = 0, o = 0, i = 0;
    for (int x = 1; x <= n; x++) {
      int c;
      cin >> c;
      switch (c) {
        case 'J':
          j++;
          break;
        case 'O':
          o++;
          break;
        case 'I':
          i++;
          break;
      }
      J[x][y] = J[x][y - 1] + j;
      O[x][y] = O[x][y - 1] + o;
      I[x][y] = I[x][y - 1] + i;
    }
  }
  while (k--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (J[d][c] - J[b - 1][c] - J[b][a - 1]) << ' ';
    cout << (O[d][c] - O[b - 1][c] - O[b][a - 1]) << ' ';
    cout << (I[d][c] - I[b - 1][c] - I[b][a - 1]) << endl;
  }
  return 0;
}
