#include <bits/stdc++.h>
using namespace std;
struct joi {
  int j;
  int o;
  int i;
};
int main() {
  int m, n, kk;
  cin >> m >> n >> kk;
  vector<joi> G(1001 * 1001 + 1);
  for (int k = 0; k < 1001; k++) {
    G[0 + 1000 * k].j = 0;
    G[0 + 1000 * k].o = 0;
    G[0 + 1000 * k].i = 0;
  }
  for (int l = 1; l <= m; l++) {
    string S;
    cin >> S;
    for (int k = 1; k <= S.length(); k++) {
      G[l * 1000 + k].j = G[l * 1000 + k - 1].j;
      G[l * 1000 + k].o = G[l * 1000 + k - 1].o;
      G[l * 1000 + k].i = G[l * 1000 + k - 1].i;
      if (S[k - 1] == 'J') {
        G[l * 1000 + k].j++;
      }
      if (S[k - 1] == 'O') {
        G[l * 1000 + k].o++;
      }
      if (S[k - 1] == 'I') {
        G[l * 1000 + k].i++;
      }
    }
  }
  for (int ii = 1; ii <= m; ii++) {
    for (int jj = 1; jj <= 10; jj++) {
      cout << G[ii * 1000 + jj].j << "," << G[ii * 1000 + jj].o << ","
           << G[ii * 1000 + jj].i << "|";
    }
    cout << endl;
  }
  for (int p = 0; p < kk; p++) {
    int ansj = 0, anso = 0, ansi = 0;
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for (int q = min(x1, x2); q <= max(x1, x2); q++) {
      ansj += G[q * 1000 + max(y1, y2)].j - G[q * 1000 + min(y1, y2) - 1].j;
      anso += G[q * 1000 + max(y1, y2)].o - G[q * 1000 + min(y1, y2) - 1].o;
      ansi += G[q * 1000 + max(y1, y2)].i - G[q * 1000 + min(y1, y2) - 1].i;
    }
    cout << ansj << " " << anso << " " << ansi << endl;
  }
}
