#include <bits/stdc++.h>
using namespace std;
struct joi {
  int j, o, i;
  joi() {
    j = 0;
    o = 0;
    i = 0;
  }
};
joi sum[1000][1000];
int m, n, k;
int main() {
  scanf("%d%d%d", &m, &n, &k);
  string row;
  cin >> row;
  if (row[0] == 'J') sum[0][0].j = 1;
  if (row[0] == 'O') sum[0][0].o = 1;
  if (row[0] == 'I') sum[0][0].i = 1;
  for (int i = 1; i < n; i++) {
    sum[0][i] = sum[0][i - 1];
    if (row[i] == 'J') sum[0][i].j++;
    if (row[i] == 'O') sum[0][i].o++;
    if (row[i] == 'I') sum[0][i].i++;
  }
  for (int i = 1; i < m; i++) {
    cin >> row;
    sum[i][0] = sum[i - 1][0];
    if (row[0] == 'J') sum[i][0].j++;
    if (row[0] == 'O') sum[i][0].o++;
    if (row[0] == 'I') sum[i][0].i++;
    for (int j = 1; j < n; j++) {
      sum[i][j].j = sum[i - 1][j].j + sum[i][j - 1].j - sum[i - 1][j - 1].j;
      sum[i][j].o = sum[i - 1][j].o + sum[i][j - 1].o - sum[i - 1][j - 1].o;
      sum[i][j].i = sum[i - 1][j].i + sum[i][j - 1].i - sum[i - 1][j - 1].i;
      if (row[j] == 'J') sum[i][j].j++;
      if (row[j] == 'O') sum[i][j].o++;
      if (row[j] == 'I') sum[i][j].i++;
    }
  }
  int a, b, c, d;
  for (int i = 0; i < k; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a -= 2;
    b -= 2;
    c--;
    d--;
    int rj = sum[c][d].j;
    int ro = sum[c][d].o;
    int ri = sum[c][d].i;
    if (a >= 0 && b >= 0) {
      rj += sum[a][b].j - sum[a][d].j - sum[c][b].j;
      ro += sum[a][b].o - sum[a][d].o - sum[c][b].o;
      ri += sum[a][b].i - sum[a][d].i - sum[c][b].i;
    } else if (a < 0) {
      rj -= sum[c][b].j;
      ro -= sum[c][b].o;
      ri -= sum[c][b].i;
    } else if (b < 0) {
      rj -= sum[a][d].j;
      ro -= sum[a][d].o;
      ri -= sum[a][d].i;
    }
    printf("%d %d %d\n", rj, ro, ri);
  }
}
