#include <bits/stdc++.h>
using namespace std;
int num[1001][1001][3];
int main() {
  int M, N, K;
  cin >> M >> N >> K;
  for (int i = 1; i <= M; i++) {
    char c[1000];
    cin >> c;
    for (int j = 1; j <= N; j++) {
      for (int k = 0; k < 3; k++) {
        num[i][j][k] =
            num[i - 1][j][k] + num[i][j - 1][k] - num[i - 1][j - 1][k];
      }
      switch (c[j - 1]) {
        case 'J':
          num[i][j][0]++;
          break;
        case 'O':
          num[i][j][1]++;
          break;
        case 'I':
          num[i][j][2]++;
          break;
      }
    }
  }
  for (int i = 0; i < K; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for (int j = 0; j < 3; j++) {
      cout << num[x2][y2][j] - num[x2][y1 - 1][j] - num[x1 - 1][y2][j] +
                  num[x1 - 1][y1 - 1][j]
           << " ";
    }
    cout << endl;
  }
}
