#include <bits/stdc++.h>
using namespace std;
pair<int, int> planet[1000][1000];
int main() {
  int m, n, k;
  cin >> m >> n;
  cin >> k;
  for (int i = 0; i < m; i++) {
    planet[i][0] = make_pair(0, 0);
    char c;
    cin >> c;
    if (c == 'J')
      planet[i][0].first++;
    else if (c == 'O')
      planet[i][0].second++;
    for (int j = 1; j < n; j++) {
      char a;
      cin >> a;
      if (a == 'J')
        planet[i][j].first = planet[i][j - 1].first + 1;
      else if (a == 'O')
        planet[i][j].second = planet[i][j - 1].first + 1;
    }
  }
  for (int i = 0; i < k; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int J = 0, O = 0, I = 0;
    for (int j = a - 1; j < c - a; j++) {
      int e = planet[j][d - 1].first - planet[j][b - 1].first;
      int f = planet[j][d - 1].second - planet[j][b - 1].second;
      J += e;
      O += f;
    }
    I = (c - a + 1) * (d - b + 1) - J - O;
    cout << J << ' ' << O << ' ' << I << endl;
  }
  return 0;
}
