#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l, ji = 0, o = 0, ai = 0, x1, x2, y1, y2;
  char ma[1000][1000];
  cin >> n >> k >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) cin >> ma[i][j];
  }
  for (int i = 0; i < l; i++) {
    cin >> y1 >> x1 >> y2 >> x2;
    for (int t = x1 - 1; t <= x2 - 1; t++) {
      for (int j = y1 - 1; j <= y2 - 1; j++) {
        if (ma[j][t] == 'J')
          ji++;
        else if (ma[j][t] == 'O')
          o++;
        else if (ma[j][t] == 'I')
          ai++;
      }
    }
    cout << ji << " " << o << " " << ai << endl;
    ji = 0;
    o = 0;
    ai = 0;
  }
}
