#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][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++) {
    long long t1 = 0, t2 = 0, t3 = 0;
    for (long long j = 0; j < N; j++) {
      if (w[i][j] == 'J')
        t1++;
      else if (w[i][j] == 'O')
        t2++;
      else
        t3++;
      if (i == 0) {
        memo[i][j][0] = t1;
        memo[i][j][1] = t2;
        memo[i][j][2] = t3;
      } else {
        memo[i][j][0] = memo[i - 1][j][0] + t1;
        memo[i][j][1] = memo[i - 1][j][1] + t2;
        memo[i][j][2] = memo[i - 1][j][2] + t3;
      }
      cout << " i" << i << " j" << j << " " << memo[i][j][0] << memo[i][j][1]
           << memo[i][j][2];
    }
    cout << endl;
  }
  for (long long i = 0; i < K; i++) {
    long long a1, a2, a3;
    a1 = memo[c[i] - 1][d[i] - 1][0] - memo[a[i] - 2][d[i] - 1][0] -
         memo[c[i] - 1][b[i] - 2][0] + memo[a[i] - 2][b[i] - 2][0];
    a2 = memo[c[i] - 1][d[i] - 1][1] - memo[a[i] - 2][d[i] - 1][1] -
         memo[c[i] - 1][b[i] - 2][1] + memo[a[i] - 2][b[i] - 2][1];
    a3 = memo[c[i] - 1][d[i] - 1][2] - memo[a[i] - 2][d[i] - 1][2] -
         memo[c[i] - 1][b[i] - 2][2] + memo[a[i] - 2][b[i] - 2][2];
    cout << a1 << " " << a2 << " " << a3 << endl;
  }
}
