#include <bits/stdc++.h>
using namespace std;
int m, n, k;
vector<string> v;
char t[1001];
void solve(int a, int b, int c, int d) {
  int j = 0, o = 0, i = 0;
  for (int x = a - 1; x < c; x++) {
    for (int y = b - 1; y < d; y++) {
      if (v[x][y] == 'J')
        j++;
      else if (v[x][y] == 'O')
        o++;
      else
        i++;
    }
  }
  printf("%d %d %d\n", j, o, i);
}
int main() {
  scanf("%d %d %d", &m, &n, &k);
  for (int i = 0; i < m; i++) {
    scanf("%s", t);
    v.push_back(t);
  }
  int a, b, c, d;
  for (int i = 0; i < k; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    solve(a, b, c, d);
  }
  return 0;
}
