#include <iostream>
#include <string>
using namespace std;
int m,n,k,imos[3][1001][1001];
string s[1000];
int main(){
	cin >> m >> n >> k;
	for(int i=1;i<=m;i++){
		cin >> s[i];
		for(int j=0;j<n;j++){
			int hoge;
			if(s[i][j]=='J') hoge=0;
			if(s[i][j]=='O') hoge=1;
			if(s[i][j]=='I') hoge=2;
			imos[0][i][j+1]=imos[0][i][j];
			imos[1][i][j+1]=imos[1][i][j];
			imos[2][i][j+1]=imos[2][i][j];
			imos[hoge][i][j+1]++;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=1;j<=m;j++){
			for(int h=1;h<=n;h++){
				imos[i][j][h]+=imos[i][j-1][h];
			}
		}
	}
	for(int i=0;i<k;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		cout << imos[0][c][d]-imos[0][a-1][d]-imos[0][c][b-1]+imos[0][a-1][b-1] << " ";
		cout << imos[1][c][d]-imos[1][a-1][d]-imos[1][c][b-1]+imos[1][a-1][b-1] << " ";
		cout << imos[2][c][d]-imos[2][a-1][d]-imos[2][c][b-1]+imos[2][a-1][b-1];
		cout << endl;
	}
	return 0;
}