#include <bits/stdc++.h>
using namespace std;
int main() {
  const int MAX_N = 1000;
  int m, n, k;
  string s[1000];
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; i++) cin >> s[i];
  int j[MAX_N + 1][MAX_N + 1], o[MAX_N + 1][MAX_N + 1];
  int i[MAX_N + 1][MAX_N + 1];
  for (int I = 0; I <= m; I++) {
    for (int J = 0; J <= n; J++) {
      if (I == 0 || J == 0)
        j[I][J] = o[I][J] = i[I][J] = 0;
      else {
        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];
        if (s[I - 1][J - 1] == 'J') j[I][J]++;
        if (s[I - 1][J - 1] == 'I') i[I][J]++;
        if (s[I - 1][J - 1] == 'O') o[I][J]++;
      }
    }
  }
  for (int I = 0; I <= m; I++)
    for (int J = 0; J <= n; J++)
      printf("%d %d %d\n", j[I][J], o[I][J], i[I][J]);
  int a, b, c, d;
  int ansi, anso, ansj;
  for (int x = 0; x < k; x++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    ansj = j[c][d] + j[a - 1][b - 1] - j[a - 1][d] - j[c][b - 1];
    anso = o[c][d] + o[a - 1][b - 1] - o[a - 1][d] - o[c][b - 1];
    ansi = i[c][d] + i[a - 1][b - 1] - i[a - 1][d] - i[c][b - 1];
    printf("%d %d %d\n", ansj, anso, ansi);
  }
  return 0;
}
