#include <bits/stdc++.h>
using namespace std;
int sum[1001][1001][3];
int main() {
  int m, n, k;
  string buff = "JOI";
  cin >> m >> n >> k;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      for (int k = 0; k < 3; k++) {
        sum[i][j][k] =
            sum[i - 1][j][k] + sum[i - 1][j][k] - sum[i - 1][j - 1][k];
      }
      sum[i][j][buff.find(c)]++;
    }
  }
  while (k--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; i < 3; i++) {
      cout << (i ? " " : "")
           << sum[c][d][i] + sum[a - 1][b - 1][i] - sum[a - 1][d][i] -
                  sum[c][b - 1][i];
    }
    puts("");
  }
}
