#include<iostream>

using namespace std;

int main(){
  int m, n, k;
  cin >> m >> n >> k;

  int J[m+1][n+1], O[m+1][n+1], I[m+1][n+1];

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

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

  for(int i = 1; i <= m; i++){
    for(int j = 0; j <= n; j++){
      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 <= m; i++){
    for(int j = 1; j <= n; j++){
      J[i][j] += J[i][j-1];
      O[i][j] += O[i][j-1];
      I[i][j] += I[i][j-1];
    }
  }

  for(int i = 0; i < k; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans_j , ans_o, ans_i;
    ans_j = J[c][d] - J[a-1][d] - J[c][b-1] + J[a-1][b-1];
    ans_o = O[c][d] - O[a-1][d] - O[c][b-1] + O[a-1][b-1];
    ans_i = I[c][d] - I[a-1][d] - I[c][b-1] + I[a-1][b-1];

    cout << ans_j << " " << ans_o << " " << ans_i << endl;
  }
}

