#include <bits/stdc++.h>
using namespace std;
int n, m, k, res[3];
int exp[4];
char planet[1001][1001];
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> planet[i][j];
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> exp[j];
    }
    for (int j = 0; j < 3; j++) {
      res[j] = 0;
    }
    for (int j = exp[0]; j <= exp[2]; j++) {
      for (int l = exp[1]; l <= exp[3]; l++) {
        if (planet[j][l] == 'J') res[0]++;
        if (planet[j][l] == 'O') res[1]++;
        if (planet[j][l] == 'I') res[2]++;
      }
    }
    for (int j = 0; j < 3; j++) {
      cout << res[j] << ' ';
    }
    cout << endl;
  }
  return 0;
}
