#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N;
  int K;
  int JOI[3][1000 + 1][1000 + 1];
  int a, b, c, d;
  string in;
  cin >> M >> N;
  cin >> K;
  for (int i = 1; i <= M; i++) {
    cin >> in;
    for (int j = 0; j < N; j++) {
      if (in[j] == 'J')
        JOI[0][i][j + 1] = 1;
      else if (in[j] == 'O')
        JOI[1][i][j + 1] = 1;
      else if (in[j] == 'I')
        JOI[2][i][j + 1] = 1;
    }
  }
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 0; k < 3; k++) {
        JOI[k][i][j] += JOI[k][i][j - 1];
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      for (int k = 0; k < 3; k++) {
        JOI[k][j][i] += JOI[k][j - 1][i];
      }
    }
  }
  for (int i = 0; i < K; i++) {
    cin >> a >> b >> c >> d;
    for (int j = 0; j < 3; j++) {
      cout << JOI[j][c][d] - JOI[j][c][b - 1] - JOI[j][a - 1][d] +
                  JOI[j][a - 1][b - 1];
      if (j != 2)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}
