#include <bits/stdc++.h>
using namespace std;
typedef pair<int, pair<int, int> > piii;
void count(piii& dp, char s) {
  if (s == 'J') {
    dp.first++;
  } else if (s == 'O') {
    dp.second.first++;
  } else {
    dp.second.second++;
  }
}
piii add(piii a, piii b) {
  piii res;
  res = a;
  res.first += b.first;
  res.second.first += b.second.first;
  res.second.second += b.second.second;
  return res;
}
piii sub(piii a, piii b) {
  piii res;
  res = a;
  res.first -= b.first;
  res.second.first -= b.second.first;
  res.second.second -= b.second.second;
  return res;
}
int main(int argc, char* argv[]) {
  int w, h, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  piii dp[h][w];
  memset(dp, 0, sizeof(dp));
  count(dp[0][0], s[0][0]);
  for (int i = 1; i < w; i++) {
    dp[0][i] = dp[0][i - 1];
    count(dp[0][i], s[0][i]);
  }
  for (int i = 1; i < h; i++) {
    dp[i][0] = dp[i - 1][0];
    count(dp[i][0], s[i][0]);
  }
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      dp[i][j] = dp[i - 1][j];
      dp[i][j] = add(dp[i][j], dp[i][j - 1]);
      dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
      count(dp[i][j], s[i][j]);
    }
  }
  for (int i = 0; i < k; i++) {
    int sx, sy, gx, gy;
    cin >> sy >> sx >> gy >> gx;
    sx--, sy--, gx--, gy--;
    piii ans = dp[gy][gx];
    if (1 <= sx) ans = sub(ans, dp[gy][sx - 1]);
    if (1 <= sy) ans = sub(ans, dp[sy - 1][gx]);
    if (1 <= sy && 1 <= sx) ans = add(ans, dp[sy - 1][sx - 1]);
    std::cout << ans.first << " " << ans.second.first << " "
              << ans.second.second << std::endl;
  }
  return 0;
}
