#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << "test";
  int h, w, kk;
  cin >> h >> w >> kk;
  string str;
  vector<string> joi;
  for (int i = 0; i < (int)(h); i++) {
    cin >> str;
    joi.push_back(str);
  }
  int mmap[3][1001][1001] = {0};
  string hit = "JOI";
  int tmp = 0;
  for (int i = (int)(0); i < (int)(3); i++) {
    for (int j = (int)(1); j < (int)(w + 1); j++) {
      if (joi[0][j - 1] == hit[i]) tmp++;
      mmap[i][1][j] = tmp;
    }
    for (int j = (int)(2); j < (int)(h + 1); j++) {
      tmp = 0;
      for (int k = (int)(1); k < (int)(w + 1); k++) {
        if (joi[j - 1][k - 1] == hit[i]) tmp++;
        mmap[i][j][k] = mmap[i][j - 1][k] + tmp;
      }
    }
  }
  for (int i = 0; i < (int)(kk); i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int t[3];
    for (int j = 0; j < (int)(3); j++) {
      t[j] = mmap[j][x2][y2] + mmap[j][x1 - 1][y1 - 1] - mmap[j][x1 - 1][y2] -
             mmap[j][x2][y1 - 1];
    }
    cout << t[0] << " " << t[1] << " " << t[2] << endl;
  }
  return 0;
}
