#include <iostream>
using namespace std;

int M, N, K;
int jt[1010][1010];
int ot[1010][1010];
int it[1010][1010];

int main() {
  cin >> M >> N >> K;
  for (int i=1; i<=M; i++) {
    int hj = 0, ho = 0, hi = 0;
    for (int j=1; j<=N; j++) {
      char c; cin >> c;

      jt[i][j] = jt[i-1][j] + hj;
      ot[i][j] = ot[i-1][j] + ho;
      it[i][j] = it[i-1][j] + hi;

      if (c == 'J') { jt[i][j]++; hj++; }
      if (c == 'O') { ot[i][j]++; ho++; }
      if (c == 'I') { it[i][j]++; hi++; }
    }
  }

  for (int i=0; i<K; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << jt[c][d] - jt[a-1][d] - jt[c][b-1] + jt[a-1][b-1] << " "
         << ot[c][d] - ot[a-1][d] - ot[c][b-1] + ot[a-1][b-1] << " "
         << it[c][d] - it[a-1][d] - it[c][b-1] + it[a-1][b-1] << "\n";
  }
  return 0;
}