#include <bits/stdc++.h>
using namespace std;
int mori[1001][1001] = {0}, umi[1001][1001] = {0}, hokkyoku[1001][1001] = {0};
int main() {
  int i, j, n, m, w, a, b, c, d, k;
  char s[2001];
  cin >> m >> n >> k;
  for (i = 1; i <= m; i++) {
    scanf("%s", s);
    for (j = 1; j <= n; j++) {
      if (s[j - 1] == 'J') mori[i][j]++;
      if (s[j - 1] == 'O') umi[i][j]++;
      if (s[j - 1] == 'I') hokkyoku[i][j]++;
      mori[i][j] =
          mori[i][j] + mori[i][j - 1] + (mori[i - 1][j] - mori[i - 1][j - 1]);
      umi[i][j] =
          umi[i][j] + umi[i][j - 1] + (umi[i - 1][j] - umi[i - 1][j - 1]);
      hokkyoku[i][j] = hokkyoku[i][j] + hokkyoku[i][j - 1] +
                       (hokkyoku[i - 1][j] - hokkyoku[i - 1][j - 1]);
    }
  }
  for (i = 0; i < k; i++) {
    cin >> a >> b >> c >> d;
    printf("%d %d %d\n",
           mori[c][d] - mori[a - 1][d] - (mori[c][b - 1] - mori[a - 1][b - 1]),
           umi[c][d] - umi[a - 1][d] - (umi[c][b - 1] - umi[a - 1][b - 1]),
           hokkyoku[c][d] - hokkyoku[a - 1][d] -
               (hokkyoku[c][b - 1] - hokkyoku[a - 1][a - 1]));
  }
  return 0;
}
