#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX = 1001;
int H, W, K;
int J[MAX][MAX], O[MAX][MAX], I[MAX][MAX];
char field[MAX][MAX];

int main(void) {
  while(cin >> H >> W >> K) {
    memset(J, 0, sizeof(J));
    memset(O, 0, sizeof(O));
    memset(I, 0, sizeof(I));
    
    for(int i = 1; i <= H; i++){
      cin >> &field[i][1];
      for(int j = 1 ; j <= W ; j++){
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];
	
        if(field[i][j] == 'J')      J[i][j]++;
        else if(field[i][j] == 'O') O[i][j]++;
        else if(field[i][j] == 'I') I[i][j]++;
      }
    }
    
    for(int i = 0 ; i < K ; i++) {
      int px, py, qx, qy;
      cin >> px >> py >> qx >> qy;
      int ansJ, ansO, ansI;
      ansJ = J[qx][qy] - J[px-1][qy] - J[qx][py-1] + J[px-1][py-1];
      ansO = O[qx][qy] - O[px-1][qy] - O[qx][py-1] + O[px-1][py-1];
      ansI = I[qx][qy] - I[px-1][qy] - I[qx][py-1] + I[px-1][py-1];
      printf("%d %d %d\n", ansJ, ansO, ansI);
    }
  }
}