#include <iostream>
using namespace std;

// masu[0]: J, masu[1]: O, masu[2]: I
int masu[1005][1005][3];

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

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      char tmp;
      cin >> tmp;
      if (tmp == 'J') {
        masu[i][j][0]++;
      } else if (tmp == 'O') {
        masu[i][j][1]++;
      } else {
        masu[i][j][2]++;
      }
    }
  }

  for (int k = 0; k < 3; k++) {
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        masu[i][j][k] += masu[i][j-1][k];
      }
    }
    for (int j = 1; j <= n; j++) {
      for (int i = 1; i <= m; i++) {
        masu[i][j][k] += masu[i-1][j][k];
      }
    }
  }

  while (num--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; i < 3; i++) {
      int ans = masu[c][d][i] - masu[a-1][d][i] - masu[c][b-1][i] + masu[a-1][b-1][i];
      cout << (i ? " " : "") << ans;
    }
    cout << endl;
  }
  return 0;
}