#include <bits/stdc++.h>
using namespace std;
const int W = 1111;
char board[W][W];
int memo[W][W][3];
int main() {
  int h, w;
  int n;
  cin >> h >> w >> n;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> board[i][j];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      for (int k = 0; k < 3; k++) {
        memo[i][j][k] =
            memo[i - 1][j][k] + memo[i][j - 1][k] - memo[i - 1][j - 1][k];
      }
      if (board[i][j] == 'J') memo[i][j][0]++;
      if (board[i][j] == 'O') memo[i][j][1]++;
      if (board[i][j] == 'I') memo[i][j][2]++;
    }
  }
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int j = 0; j < 3; j++) {
      int ans = memo[c][d][j] - memo[c][b - 1][j] - memo[a - 1][d][j] +
                memo[a - 1][b - 1][j];
      printf("%d ", ans);
    }
    puts("");
  }
}
