#include <bits/stdc++.h>
using namespace std;
class JOI {
 public:
  int j, o, i;
  JOI() : j(0), o(0), i(0) {}
  JOI(int a, int b, int c) : j(a), o(b), i(c){};
  JOI operator+(JOI obj) {
    return JOI(this->j + obj.j, this->o + obj.o, this->i + obj.i);
  }
  JOI operator-(JOI obj) {
    return JOI(this->j - obj.j, this->o - obj.o, this->i - obj.i);
  }
};
vector<string> data;
vector<vector<JOI>> dp(1001, vector<JOI>(1001));
int m, n;
void makeDP() {
  for (long long i = 0; i < (long long)(m); i++) {
    for (long long j = 0; j < (long long)(n); j++) {
      JOI ad(0, 0, 0);
      if (data[i][j] == 'J') ad.j++;
      if (data[i][j] == 'O') ad.o++;
      if (data[i][j] == 'I') ad.i++;
      JOI cent, right, under;
      if (i - 1 >= 0 && j - 1 >= 0) cent = dp[i - 1][j - 1];
      if (i - 1 >= 0) right = dp[i - 1][j];
      if (j - 1 >= 0) under = dp[i][j - 1];
      dp[i][j] = right + under - cent + ad;
    }
  }
}
int main() {
  cin >> m >> n;
  int q;
  cin >> q;
  data.resize(n);
  for (long long i = 0; i < (long long)(m); i++) cin >> data[i];
  makeDP();
  for (long long i = 0; i < (long long)(q); i++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    x1--, y1--, x2--, y2--;
    JOI a, b, c;
    if (y1 - 1 >= 0) a = dp[y1 - 1][x2];
    if (x1 - 1 >= 0) b = dp[y2][x1 - 1];
    if (y1 - 1 >= 0 && x1 - 1 >= 0) c = dp[y1 - 1][x1 - 1];
    JOI res = dp[y2][x2];
    cout << res.j << " " << res.o << " " << res.i << endl;
  }
}
