#include <bits/stdc++.h>
using namespace std;
string p[1000];
int M, N, K;
int a, b, c, d;
int main() {
  cin >> M >> N >> K;
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < K; i++) {
    int J = 0, O = 0, I = 0;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    for (int x = a; x < c; x++) {
      for (int y = b; y < d; y++) {
        if (p[x][y] == 'J')
          J++;
        else if (p[x][y] == 'O')
          O++;
        else
          I++;
      }
    }
    cout << J << " " << O << " " << I << endl;
  }
  return 0;
}
