#include <bits/stdc++.h>
using namespace std;
char p[1000][1000];
int M, N, K;
vector<int> count(int a, int b, int c, int d) {
  int J = 0, O = 0, I = 0;
  a--;
  b--;
  c--;
  d--;
  for (int x = a; x < c; x++) {
    for (int y = b; y < d; y++) {
      if (p[x][y] == 'J')
        J++;
      else if (p[x][y] == 'O')
        O++;
      else
        I++;
    }
  }
  return {J, O, I};
}
int main() {
  cin >> M >> N >> K;
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  const int L = 10;
  vector<vector<vector<int> > > v = vector<vector<vector<int> > >(M / L);
  for (int i = 0; i < M / L; i++) {
    v[i] = vector<vector<int> >(N / L);
    for (int j = 0; j < N / L; j++) {
      v[i][j] = vector<int>(3);
      vector<int> v1 =
          count(L * i + 1, L * j + 1, L * (i + 1) + 1, L * (j + 1) + 1);
      v[i][j][0] = v1[0];
      v[i][j][1] = v1[1];
      v[i][j][2] = v1[2];
    }
  }
  for (int i = 0; i < K; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int an = a / L, bn = b / L, cn = (c - 1) / L, dn = (d - 1) / L;
    if (an != cn && bn != dn && cn - an > 1 && dn - bn > 1) {
      vector<int> v1 = {0, 0, 0};
      for (int x = an; x < cn; x++) {
        for (int y = bn; y < dn; y++) {
          v1[0] += v[x][y][0];
          v1[1] += v[x][y][1];
          v1[2] += v[x][y][2];
        }
      }
      vector<int> v2 = count(a, b, c + 1, (bn + 1) * L);
      vector<int> v3 = count(a, (bn + 1) * L, (an + 1) * L, d + 1);
      vector<int> v4 = count((an + 1) * L, dn * L, c + 1, d + 1);
      vector<int> v5 = count(cn * L, (bn + 1) * L, c + 1, dn * L);
      v1[0] = v2[0] + v3[0] + v4[0] + v5[0];
      v1[1] = v2[1] + v3[1] + v4[1] + v5[1];
      v1[2] = v2[2] + v3[2] + v4[2] + v5[2];
      cout << v1[0] << " " << v1[1] << " " << v1[2] << endl;
    } else {
      vector<int> v1 = count(a, b, c + 1, d + 1);
      cout << v1[0] << " " << v1[1] << " " << v1[2] << endl;
    }
  }
  return 0;
}
