#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  while (cin >> h >> w) {
    int k;
    cin >> k;
    static short int J[1000][1000], O[1000][1000], I[1000][1000];
    static short int size_j[1000], size_o[1000], size_i[1000];
    for (int i = 0; i < h; i++) {
      size_j[i] = size_o[i] = size_i[i] = 0;
      for (int j = 0; j < w; j++) {
        char c;
        cin >> c;
        if (c == 'J')
          J[i][size_j[i]++] = j;
        else if (c == 'O')
          O[i][size_o[i]++] = j;
        else if (c == 'I')
          I[i][size_i[i]++] = j;
      }
    }
    int y1, x1, y2, x2;
    for (int i = 0; i < k; i++) {
      int ans_j = 0, ans_o = 0, ans_i = 0;
      cin >> y1 >> x1 >> y2 >> x2;
      y1--;
      x1--;
      y2--;
      x2--;
      for (int j = y1; j <= y2; j++) {
        ans_j += upper_bound(J[j], J[j] + size_j[j], x2) -
                 lower_bound(J[j], J[j] + size_j[j], x1);
        ans_o += upper_bound(O[j], O[j] + size_o[j], x2) -
                 lower_bound(O[j], O[j] + size_o[j], x1);
        ans_i += upper_bound(I[j], I[j] + size_i[j], x2) -
                 lower_bound(I[j], I[j] + size_i[j], x1);
      }
      cout << ans_j << ' ' << ans_o << ' ' << ans_i << endl;
    }
  }
  return 0;
}
