#include <bits/stdc++.h>
using namespace std;
struct joi {
  int j;
  int o;
  int i;
};
int main() {
  int m, n, kk;
  cin >> m >> n >> kk;
  joi G[1002][1002];
  for (int k = 0; k < 1001; k++) {
    G[k][0] = {0, 0, 0};
  }
  for (int l = 1; l <= m; l++) {
    string S;
    cin >> S;
    for (int k = 1; k < S.length(); k++) {
      if (S[k] == 'J') {
        G[l][k].j = G[l][k - 1].j + 1;
      }
      if (S[k] == 'O') {
        G[l][k].o = G[l][k - 1].o + 1;
      }
      if (S[k] == 'I') {
        G[l][k].i = G[l][k - 1].i + 1;
      }
    }
  }
  for (int p = 0; p < kk; p++) {
    int ansj = 0, anso = 0, ansi = 0;
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for (int q = x1; q <= x2;) {
      ansj += G[q][y2].j - G[q][y1].j;
      anso += G[q][y2].o - G[q][y1].o;
      ansi += G[q][y2].i - G[q][y1].i;
    }
    cout << ansj << " " << anso << " " << ansi << endl;
  }
}
