#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int> > psum(vector<string>& grid,char c)
{
	int m=grid.size(),n=grid[0].size();
	vector<vector<int> > a(m+1,vector<int>(n+1));
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+(grid[i-1][j-1]==c);
	return a;
}

int calc(vector<vector<int> >& a,int i1,int j1,int i2,int j2)
{
	return a[i2][j2]-a[i1][j2]-a[i2][j1]+a[i1][j1];
}

int main()
{
	for(int m,n,k;cin>>m>>n>>k;){
		vector<string> grid(m);
		for(int i=0;i<m;i++)
			cin>>grid[i];
		
		vector<vector<int> > js=psum(grid,'J'),os=psum(grid,'O'),is=psum(grid,'I');
		
		while(k--){
			int a,b,c,d; cin>>a>>b>>c>>d;
			cout<<calc(js,a-1,b-1,c,d)<<' ';
			cout<<calc(os,a-1,b-1,c,d)<<' ';
			cout<<calc(is,a-1,b-1,c,d)<<endl;
		}
	}
	
	return 0;
}