#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

template <typename T>
struct towdimBIT
{
private:
	vector< vector<T> > array;
	const int n;
	const int m;
 
public:
	towdimBIT(int _n,int _m):
		array(_n+1,vector<T>(_m+1,0)), n(_n),m(_m){}
 
	// (1,1) ~ (x,y) ruisekiwa
	T sum(int x,int y) {
		T s = 0;
		for(int i=x;i>0;i-=i&(-i))
			for(int j=y;j>0;j-=j&(-j))
				s += array[i][j];
		return s;
	}

	// [(x1,y1),(x2,y2)] no souwa
	T sum(int x1,int y1,int x2,int y2){
		return sum(x2,y2) - sum(x1-1,y2) - sum(x2,y1-1) + sum(x1-1,y1-1);
	}
 
	void add(int x,int y,T k) {
		for(int i=x;i<=n;i+=i&(-i))
			for(int j=y;j<=m;j+=j&(-j))
				array[i][j] += k;
	}
};
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m,q;
	cin>>n>>m>>q;
	towdimBIT<int> J(n,m),I(n,m),O(n,m);

	FOR(i,0,n){
		string s;
		cin>>s;
		FOR(j,0,m){
			char x;
			x = s[j];
			if(x=='J')J.add(i+1,j+1,1);
			if(x=='I')I.add(i+1,j+1,1);
			if(x=='O')O.add(i+1,j+1,1);
		}
	}

	FOR(i,0,q){
		ll x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		cout<<J.sum(x1,y1,x2,y2)<<" ";
		cout<<O.sum(x1,y1,x2,y2)<<" ";
		cout<<I.sum(x1,y1,x2,y2)<<endl;
	}
}
