#include <bits/stdc++.h>

using namespace std;

int cumj[1010][1010];
int cumo[1010][1010];
int cumi[1010][1010];

int main(void) {
  int m, n, k;
  cin >> m >> n >> k;

  vector<string> s(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    for (int j = 0; j < n; j++) {
      cumj[i + 1][j + 1] = s[i][j] == 'J';
      cumo[i + 1][j + 1] = s[i][j] == 'O';
      cumi[i + 1][j + 1] = s[i][j] == 'I';
    }
  }

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      cumj[i][j] += cumj[i - 1][j] + cumj[i][j - 1] - cumj[i - 1][j - 1];
      cumo[i][j] += cumo[i - 1][j] + cumo[i][j - 1] - cumo[i - 1][j - 1];
      cumi[i][j] += cumi[i - 1][j] + cumi[i][j - 1] - cumi[i - 1][j - 1];
    }
  }

  for (int i = 0; i < k; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << cumj[c][d] - cumj[a - 1][d] - cumj[c][b - 1] + cumj[a - 1][b - 1] << " ";
    cout << cumo[c][d] - cumo[a - 1][d] - cumo[c][b - 1] + cumo[a - 1][b - 1] << " ";
    cout << cumi[c][d] - cumi[a - 1][d] - cumi[c][b - 1] + cumi[a - 1][b - 1] << endl;
  }

  return 0;
}
