#include <iostream>

using namespace std;

int n, m;
int jn[1001][1001];
int oc[1001][1001];
int ic[1001][1001];

int main()
{
  char c;
  int k, s, t, u, v;

  while(cin>>m>>n && n+m){
    cin >> k;
    for(int i = 0; i <= m; ++i)
      for(int j = 0; j <= n; ++j)
	jn[i][j] = oc[i][j] = ic[i][j] = 0;

    for(int i = 1; i <= m; ++i){
      s = t = u = 0;
      for(int j = 1; j <= n; ++j){
	cin >> c;
	if(c == 'J') ++s;
	if(c == 'O') ++t;
	if(c == 'I') ++u;

	jn[i][j] += (s+jn[i-1][j]);
	oc[i][j] += (t+oc[i-1][j]);
	ic[i][j] += (u+ic[i-1][j]);
      }
    }

    while(k--){
      cin >> s >> t >> u >> v;
      cout << (jn[u][v]-jn[u][t-1]-jn[s-1][v]+jn[s-1][t-1]) << " " << flush;
      cout << (oc[u][v]-oc[u][t-1]-oc[s-1][v]+oc[s-1][t-1]) << " " << flush;
      cout << (ic[u][v]-ic[u][t-1]-ic[s-1][v]+ic[s-1][t-1]) << endl;
    }
  }

  return 0;
}