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