#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long a[100000] = {}, b[100000] = {}, c[100000] = {}, d[100000] = {};
long long memo[100][100][100][3] = {};
char w[1000][1000] = {};
signed main() {
  long long M, N, K;
  cin >> M >> N >> K;
  for (long long i = 0; i < M; i++) {
    for (long long j = 0; j < N; j++) {
      cin >> w[i][j];
    }
  }
  for (long long i = 0; i < K; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (long long i = 0; i < M; i++) {
    for (long long j = 0; j < N; j++) {
      long long t1 = 0, t2 = 0, t3 = 0;
      for (long long k = j; k < N; k++) {
        if (w[i][k] == 'J')
          t1++;
        else if (w[i][k] == 'O')
          t2++;
        else
          t3++;
        memo[j][k][i][0] = t1;
        memo[j][k][i][1] = t2;
        memo[j][k][i][2] = t3;
      }
    }
  }
  for (long long i = 0; i < K; i++) {
    long long t1 = 0, t2 = 0, t3 = 0;
    for (long long j = a[i] - 1; j < c[i]; j++) {
      t1 += memo[b[i] - 1][d[i] - 1][j][0];
      t2 += memo[b[i] - 1][d[i] - 1][j][1];
      t3 += memo[b[i] - 1][d[i] - 1][j][2];
    }
    cout << t1 << " " << t2 << " " << t3 << endl;
  }
}
