#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;
int main() {
  int M, N;
  cin >> M >> N;
  int K;
  cin >> K;
  map<char, int> mp;
  mp['J'] = 0;
  mp['O'] = 1;
  mp['I'] = 2;
  vector<vector<vector<int>>> nums(M + 1,
                                   vector<vector<int>>(N + 1, vector<int>(3)));
  vector<vector<vector<int>>> sums(M + 1,
                                   vector<vector<int>>(N + 1, vector<int>(3)));
  for (int i = 0; i < M; ++i) {
    string st;
    cin >> st;
    for (int j = 0; j < N; ++j) {
      nums[i + 1][j + 1][mp[st[j]]]++;
    }
  }
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= N; ++j) {
    }
  }
  for (int k = 0; k < 3; ++k) {
    for (int i = 1; i <= M; ++i) {
      for (int j = 1; j <= N; ++j) {
        sums[i][j][k] = sums[i][j - 1][k] + sums[i - 1][j][k] -
                        sums[i - 1][j - 1][k] + nums[i][j][k];
      }
    }
  }
  for (int i = 0; i < K; ++i) {
    int a, b, c, d;
    cin >> b >> a >> d >> c;
    b--;
    a--;
    vector<int> anss(3);
    for (int j = 0; j < 3; ++j) {
      anss[j] = sums[d][c][j] - sums[d][a][j] - sums[b][c][j] + sums[b][a][j];
    }
    cout << anss[0] << " " << anss[1] << " " << anss[2] << endl;
  }
  return 0;
}
