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