#include <bits/stdc++.h>
using namespace std;
char elia[1000][1001];
long long jwa[1001][1001], owa[1001][1001], iwa[1001][1001];
int main(void) {
  long long i, j, m, n, k, js, os, is, jsum, osum, isum, a, b, c, d;
  cin >> m >> n >> k;
  for (i = 0; i < m; i++) cin >> elia[i];
  for (i = 0; i <= m; i++) jwa[i][0] = 0, owa[i][0] = 0, iwa[i][0] = 0;
  for (i = 0; i <= n; i++) jwa[0][i] = 0, owa[0][i] = 0, iwa[0][i] = 0;
  cout << 111111111 << endl;
  for (i = 1; i <= n; i++) {
    if (elia[0][i - 1] == 'J') js++;
    if (elia[0][i - 1] == 'O') os++;
    if (elia[0][i - 1] == 'I') is++;
    jwa[1][i] = js;
    owa[1][i] = os;
    iwa[1][i] = is;
  }
  for (i = 1; i <= m; i++) {
    js = 0, os = 0, is = 0;
    for (j = 1; j <= n; j++) {
      if (elia[i - 1][j - 1] == 'J') js++;
      jwa[i][j] = jwa[i - 1][j] + js;
      if (elia[i - 1][j - 1] == 'O') os++;
      owa[i][j] = owa[i - 1][j] + os;
      if (elia[i - 1][j - 1] == 'I') is++;
      iwa[i][j] = iwa[i - 1][j] + is;
    }
  }
  for (i = 0; i < k; i++) {
    cin >> a >> b >> c >> d;
    a--;
    b--;
    jsum = jwa[c][d] - jwa[a][d] - jwa[c][b] + jwa[a][b];
    osum = owa[c][d] - owa[a][d] - owa[c][b] + owa[a][b];
    isum = iwa[c][d] - iwa[a][d] - iwa[c][b] + iwa[a][b];
    cout << jsum << ' ' << osum << ' ' << isum << endl;
  }
  return 0;
}
