#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  char JOI[1005][1005];
  cin >> m >> n;
  int k;
  cin >> k;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) cin >> JOI[i][j];
  int a, b, c, d;
  while (cin >> a >> b >> c >> d) {
    int jan = 0;
    int ocean = 0;
    int ice = 0;
    for (int h = a; h <= c; h++) {
      for (int w = b; w >= b && w <= d; w++) {
        if (JOI[h][w] == 'J')
          jan++;
        else if (JOI[h][w] == 'O')
          ocean++;
        else if (JOI[h][w] == 'I')
          ice++;
      }
    }
    cout << jan << " " << ocean << " " << ice;
    cout << endl;
  }
}
