#include <bits/stdc++.h>
int w[1000][1000][3];
int ww[100000][3];
int hen(char a) {
  if (a == 'J') {
    return 0;
  }
  if (a == 'O') {
    return 1;
  }
  if (a == 'I') {
    return 2;
  }
}
int main(void) {
  int m, n;
  int k;
  {
    scanf("%d %d", &m, &n);
    scanf("%d", &k);
  }
  {
    char e[2000];
    for (int i = 0; i < m; i++) {
      scanf("%s", e);
      for (int ii = 0; ii < n; ii++) {
        if (ii == 0) {
          if (i == 0) {
            w[i][ii][0] = 0;
            w[i][ii][1] = 0;
            w[i][ii][2] = 0;
            w[i][ii][hen(e[ii])]++;
          } else {
            w[i][ii][0] = w[i - 1][ii][0];
            w[i][ii][1] = w[i - 1][ii][1];
            w[i][ii][2] = w[i - 1][ii][2];
            w[i][ii][hen(e[ii])]++;
          }
        } else {
          if (i == 0) {
            w[i][ii][0] = w[i][ii - 1][0];
            w[i][ii][1] = w[i][ii - 1][1];
            w[i][ii][2] = w[i][ii - 1][2];
            w[i][ii][hen(e[ii])]++;
          } else {
            w[i][ii][0] =
                w[i - 1][ii][0] + w[i][ii - 1][0] - w[i - 1][ii - 1][0];
            w[i][ii][1] =
                w[i - 1][ii][1] + w[i][ii - 1][1] - w[i - 1][ii - 1][1];
            w[i][ii][2] =
                w[i - 1][ii][2] + w[i][ii - 1][2] - w[i - 1][ii - 1][2];
            w[i][ii][hen(e[ii])]++;
          }
        }
      }
    }
  }
  {
    int a, b, c, d;
    for (int i = 0; i < k; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      ww[k][0] = w[c - 1][d - 1][0] + w[a - 1][b - 1][0] - w[c - 1][b - 1][0] -
                 w[a - 1][d - 1][0];
      ww[k][1] = w[c - 1][d - 1][1] + w[a - 1][b - 1][1] - w[c - 1][b - 1][1] -
                 w[a - 1][d - 1][1];
      ww[k][2] = w[c - 1][d - 1][2] + w[a - 1][b - 1][2] - w[c - 1][b - 1][2] -
                 w[a - 1][d - 1][2];
    }
  }
  {
    for (int i = 0; i < k; i++) {
      printf("%d %d %d", ww[i][0], ww[i][1], ww[i][2]);
    }
  }
  return 0;
}
