#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  char joi[4] = "JOI";
  char mp[1001][1001][3];
  cin >> m >> n >> k;
  char t[1001];
  memset(mp, 0, sizeof(mp));
  for (int i = 1; i <= m; ++i) {
    cin >> t;
    for (int j = 1; j <= n; ++j) {
      for (int l = 0; l < 3; ++l)
        mp[i][j][l] = mp[i][j - 1][l] + mp[i - 1][j][l] - mp[i - 1][j - 1][l];
      for (int l = 0; l < 3; ++l)
        if (t[j - 1] == joi[l]) {
          ++mp[i][j][l];
          break;
        }
    }
  }
  int ans[3];
  for (int i = 0; i < k; ++i) {
    int yb, xb, ye, xe;
    cin >> yb >> xb >> ye >> xe;
    for (int j = 0; j < 3; ++j)
      ans[j] = mp[ye][xe][j] - mp[yb - 1][xe][j] - mp[ye][xb - 1][j] +
               mp[yb - 1][xb - 1][j];
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
  }
  return 0;
}
