#include <bits/stdc++.h>
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
  char tmp[3] = {'J', 'O', 'I'};
  int a, b, n;
  cin >> a >> b >> n;
  vector<string> in(a);
  int dp[1010][1010][3] = {0};
  for (int i = 0; i < a; i++) cin >> in[i];
  for (int i = 1; i < a + 1; i++)
    for (int j = 1; j < b + 1; j++)
      for (int k = 0; k < 3; k++) {
        dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k] - dp[i - 1][j - 1][k];
        if ((char)in[i - 1][j - 1] == tmp[k]) dp[i][j][k]++;
      }
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int out[3] = {0};
    for (int j = 0; j < 3; j++)
      out[j] =
          dp[c][d][j] - dp[c][b - 1][j] - dp[a - 1][d][j] + dp[a - 1][b - 1][j];
    cout << out[0] << " " << out[1] << " " << out[2] << endl;
  }
}
