#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-12;
const int maxn = 1005;
int n, m, Q;
string a[maxn];
int s[maxn][maxn][3];
char pat[] = {'J', 'O', 'I'};
void ReadData() {
  cin >> n >> m >> Q;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i] = ' ' + a[i];
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k < 3; k++)
        s[i][j][k] = s[i - 1][j][k] + s[i][j - 1][k] + (a[i][j] == pat[k]) -
                     s[i - 1][j - 1][k];
    }
  while (Q--) {
    int x, y, u, v;
    cin >> x >> y >> u >> v;
    for (int k = 0; k < 3; k++)
      cout << s[u][v][k] - s[x - 1][v][k] - s[u][y - 1][k] + s[x - 1][y - 1][k]
           << " ";
    cout << "\n";
  }
}
void Process() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ReadData();
  Process();
}
