#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
  int r, c, n;
  cin >> r >> c >> n;
  string s[r];
  for (int i = 0; i < r; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    int J, O, I = O = J = 0;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    for (int j = a; j < c + 1; j++) {
      for (int k = b; k < d + 1; k++) {
        if (s[j][k] == 'J')
          J++;
        else if (s[j][k] == 'O')
          O++;
        else
          I++;
      }
    }
    cout << J << " " << O << " " << I << endl;
  }
}
