#include <bits/stdc++.h>
using namespace std;
char a[10000][10000];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  string b;
  for (int i = 0; i < n; i++) {
    cin >> b;
    for (int j = 0; j < m; j++) {
      a[i][j] = b[j];
    }
  }
  for (int z = 0; z < k; z++) {
    int c[2], d[2];
    cin >> c[0] >> c[1] >> d[0] >> d[1];
    c[0]--;
    c[1]--;
    int j = 0, o = 0, i = 0;
    for (int y = c[0]; y < d[0]; y++) {
      for (int x = c[1]; x < d[1]; x++) {
        switch (a[y][x]) {
          case 'J':
            j++;
            break;
          case 'O':
            o++;
            break;
          case 'I':
            i++;
            break;
        }
      }
    }
    cout << j << " " << o << " " << i << endl;
  }
}
