#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int m, n, k;
inline int hash_(char c) { return ((c == 'J') ? 0 : ((c == 'O') ? 1 : 2)); }
int imos[3][1234][1234];
int main() {
  cin >> m >> n;
  cin >> k;
  for (int i = 0; i < m; ++i) {
    char str[1234];
    cin >> str;
    for (int j = 0; j < n; ++j) {
      int id = hash_(str[j]);
      imos[id][i + 1][j + 1]++;
    }
  }
  for (int id = 0; id < 3; ++id) {
    for (int j = 0; j < n + 1; ++j) {
      for (int i = 0; i < m + 1; ++i) {
        imos[id][i + 1][j] += imos[id][i][j];
      }
    }
  }
  for (int id = 0; id < 3; ++id) {
    for (int j = 0; j < n + 1; ++j) {
      for (int i = 0; i < m + 1; ++i) {
        imos[id][i][j + 1] += imos[id][i][j];
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a;
    --b;
    for (int id = 0; id < 3; ++id) {
      int ans =
          imos[id][c][d] + imos[id][a][b] - imos[id][a][d] - imos[id][b][c];
      cout << ans << " \n"[id == 2];
    }
  }
  return 0;
}
