#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  int N, M, K;
  int h;
  int num;
  int DP[1000][1000] = {};
  int sumplace[1000][1000][3] = {};
  int thirdplace[1000][1000][3] = {};
  int answer[3] = {};
  cin >> N >> M >> K;
  for (int p = 0; p <= N - 1; p++) {
    cin >> a;
    for (int i = 0; i <= M - 1; i++) {
      if (a[i] == 'J') thirdplace[p][i][0]++;
      if (a[i] == 'O') thirdplace[p][i][1]++;
      if (a[i] == 'I') thirdplace[p][i][2]++;
    }
  }
  for (int p = 0; p <= K - 1; p++) {
    for (int i = 0; i <= 3; i++) {
      cin >> h;
      DP[p][i] = h;
    }
  }
  for (int p = 0; p <= N - 1; p++) {
    for (int i = 0; i <= M - 1; i++) {
      for (int t = 0; t <= 2; t++) {
        sumplace[p][i][t] = thirdplace[p][i][t] + sumplace[p - 1][i][t] +
                            sumplace[p][i - 1][t] - sumplace[p - 1][i - 1][t];
      }
    }
  }
  for (int i = 0; i <= K - 1; i++) {
    for (int t = 0; t <= 2; t++) {
      answer[t] = sumplace[DP[i][2] - 1][DP[i][3] - 1][t] -
                  sumplace[DP[i][2] - 1][DP[i][1] - 2][t] -
                  sumplace[DP[i][0] - 2][DP[i][3] - 1][t] +
                  sumplace[DP[i][0] - 2][DP[i][1] - 2][t];
    }
    cout << answer[0] << " " << answer[1] << " " << answer[2] << endl;
  }
  return 0;
}
