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