#include <bits/stdc++.h>
using namespace std;
int main() {
  int m = 0, n = 0, k = 0;
  scanf("%d%d", &m, &n);
  scanf("%d", &k);
  char** arr = new char*[m];
  for (int i = 0; i < m; i++) {
    arr[i] = new char[n];
    scanf("%s", arr[i]);
  }
  for (int i = 0; i < k; i++) {
    int a = 0, b = 0, c = 0, d = 0;
    int nJ = 0, nO = 0, nI = 0;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int j = a - 1; j < c; j++) {
      for (int k = b - 1; k < d; k++) {
        switch (arr[j][k]) {
          case 'J':
            nJ++;
            break;
          case 'O':
            nO++;
            break;
          case 'I':
            nI++;
            break;
        }
      }
    }
    printf("%d %d %d\n", nJ, nO, nI);
  }
  return 0;
}
