#include <bits/stdc++.h>
using namespace std;
int M, N, K;
char map[1010][1010];
int main() {
  cin >> M >> N >> K;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      cin >> map[i][j];
    }
  }
  for (int i = 0; i < K; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int J = 0, O = 0, I = 0;
    for (int x = b - 1; x < d; x++) {
      for (int y = a - 1; y < c; y++) {
        char c = map[y][x];
        if (c == 'J') J++;
        if (c == 'O') O++;
        if (c == 'I') I++;
      }
    }
    cout << J << " " << O << " " << I << "\n";
  }
  return 0;
}
