#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
int f(char c) {
  if (c == 'J') return 0;
  if (c == 'O') return 1;
  if (c == 'I') return 2;
}
signed main() {
  int M, N, K;
  cin >> M >> N >> K;
  static int sum[3][10][10] = {};
  for (int i = (0); i < (M); i++) {
    for (int j = (0); j < (N); j++) {
      char c;
      cin >> c;
      sum[f(c)][i][j]++;
    }
  }
  for (int i = (0); i < (M); i++) {
    for (int k = (0); k < (3); k++)
      for (int j = (0); j < (N); j++) sum[k][i + 1][j] += sum[k][i][j];
    for (int j = (0); j < (N); j++) {
      for (int k = (0); k < (3); k++) sum[k][i][j + 1] += sum[k][i][j];
    }
  }
  for (int i = (0); i < (K); i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << sum[0][c - 1][d - 1] - sum[0][a - 2][d - 1] - sum[0][c - 1][b - 2] +
                sum[0][a - 2][b - 2]
         << " ";
    cout << sum[1][c - 1][d - 1] - sum[1][a - 2][d - 1] - sum[1][c - 1][b - 2] +
                sum[1][a - 2][b - 2]
         << " ";
    cout << sum[2][c - 1][d - 1] - sum[2][a - 2][d - 1] - sum[2][c - 1][b - 2] +
                sum[2][a - 2][b - 2]
         << endl;
  }
  return 0;
}
