#include <bits/stdc++.h>
using namespace std;
int m, n, k, a, b, c, d;
char in[1000][1001];
int JOI[3][1001][1001];
int main() {
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; i++) {
    scanf("%s", in[i]);
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (in[i - 1][j - 1] == 'J')
        JOI[0][i][j] = 1;
      else if (in[i - 1][j - 1] == 'O')
        JOI[1][i][j] = 1;
      else if (in[i - 1][j - 1] == 'I')
        JOI[2][i][j] = 1;
    }
  }
  for (int i = 0; i < 3; i++)
    for (int j = 1; j <= m; j++)
      for (int l = 1; l <= n; l++)
        printf(l < n ? "%2d " : "%2d\n", JOI[i][j][k]);
  for (int i = 2; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      for (int l = 0; l < 3; l++) JOI[l][i][j] += JOI[l][i - 1][j];
    }
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      for (int l = 0; l < 3; l++) JOI[l][j][i] += JOI[l][j][i - 1];
    }
  for (int i = 0; i < k; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int j = 0; j < 3; j++) {
      int ans = JOI[j][c][d] - JOI[j][a - 1][d] - JOI[j][c][b - 1] +
                JOI[j][a - 1][b - 1];
      printf(j < 2 ? "%d " : "%d\n", ans);
    }
  }
  return 0;
}
