#include <bits/stdc++.h>
using namespace std;
const int M = 1000;
const int N = 1000;
const int K = 100000;
char joi[M][N];
void check(int a, int b, int c, int d) {
  int jn = 0;
  int on = 0;
  int in = 0;
  for (int i = a; i <= c; ++i) {
    for (int j = b; j <= d; ++j) {
      if (joi[i][j] == 'J') jn++;
      if (joi[i][j] == 'O') on++;
      if (joi[i][j] == 'I') in++;
    }
  }
  cout << jn << " " << on << " " << in << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m, n, k;
  cin >> m >> n >> k;
  for (int i = 0; i != m; ++i) {
    for (int j = 0; j != n; ++j) {
      cin >> joi[i][j];
    }
  }
  for (int i = 0; i != k; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;
    check(a, b, c, d);
  }
  return 0;
}
