#include <bits/stdc++.h>
using namespace std;
int m, n, k, J[1010][1010], O[1010][1010], I[1010][1010];
string s[1010];
void solve() {
  cin >> n >> m;
  cin >> k;
  memset(J, 0, sizeof(J));
  memset(O, 0, sizeof(O));
  memset(I, 0, sizeof(I));
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      int jj = 0, oo = 0, ii = 0;
      if (s[i][j] == 'J')
        jj = 1;
      else if (s[i][j] == 'O')
        oo = 1;
      else
        ii = 1;
      J[i + 1][j + 1] = jj + J[i][j + 1] + J[i + 1][j] - J[i][j];
      O[i + 1][j + 1] = oo + O[i][j + 1] + O[i + 1][j] - O[i][j];
      I[i + 1][j + 1] = ii + I[i][j + 1] + I[i + 1][j] - I[i][j];
    }
  }
  int a, b, c, d;
  for (int i = 0; i < (int)(k); i++) {
    cin >> a >> b >> c >> d;
    c++;
    d++;
    int jj = J[c][d] - J[c][b] - J[a][d] + J[a][b];
    int oo = O[c][d] - O[c][b] - O[a][d] + O[a][b];
    int ii = I[c][d] - I[c][b] - I[a][d] + I[a][b];
    cout << jj << " " << oo << " " << ii << endl;
  }
}
int main() {
  solve();
  return 0;
}
