#include <bits/stdc++.h>
using namespace std;
int j_wa[1005][1005], o_wa[1005][1005], i_wa[1005][1005];
int ans, j, i, o, a, b, c, d, n, m, k;
char planet;
int main() {
  cin >> m >> n >> k;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> planet;
      if (planet == 'J') j_wa[j][i]++;
      if (planet == 'O') o_wa[j][i]++;
      if (planet == 'I') i_wa[j][i]++;
      j_wa[j][i] += j_wa[j - 1][i];
      o_wa[j][i] += o_wa[j - 1][i];
      i_wa[j][i] += i_wa[j - 1][i];
    }
    for (int j = 1; j <= n; j++) {
      j_wa[j][i] += j_wa[j][i - 1];
      o_wa[j][i] += o_wa[j][i - 1];
      i_wa[j][i] += i_wa[j][i - 1];
    }
  }
  for (int i = 0; i < k; i++) {
    j = 0, o = 0, i = 0;
    cin >> a >> b >> c >> d;
    j = j_wa[d][c], o = o_wa[d][c], i = i_wa[d][c];
    j = j - j_wa[b - 1][c] - j_wa[d][a - 1];
    o = o - o_wa[b - 1][c] - o_wa[d][a - 1];
    i = i - i_wa[b - 1][c] - i_wa[d][a - 1];
    j += j_wa[b - 1][a - 1];
    o += o_wa[b - 1][a - 1];
    i += i_wa[b - 1][a - 1];
    printf("%d %d %d\n", j, o, i);
  }
  return 0;
}
