#include <bits/stdc++.h>
using namespace std;

int J[1010][1010], O[1010][1010], I[1010][1010];
int n, m, k;

int main()
{
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      char c;
      cin >> c;
      J[i][j] = c == 'J';
      O[i][j] = c == 'O';
      I[i][j] = c == 'I';
    }
  }

  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      J[i][j] += J[i][j - 1];
      O[i][j] += O[i][j - 1];
      I[i][j] += I[i][j - 1];
    }
  }

  for (int j = 1; j <= m; j++){
    for (int i = 0; i <= n; i++){
      J[i][j] += J[i - 1][j];
      O[i][j] += O[i - 1][j];
      I[i][j] += I[i - 1][j];
    }
  }

  for (int i = 0; i < k; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--;
    cout << (J[c][d] - J[a][d]) - (J[c][b] - J[a][b]) << " ";
    cout << (O[c][d] - O[a][d]) - (O[c][b] - O[a][b]) << " ";
    cout << (I[c][d] - I[a][d]) - (I[c][b] - I[a][b]) << endl;
  }
}