#include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

const int psumsize=1001;
int
psum_J[psumsize][psumsize],
psum_O[psumsize][psumsize],
psum_I[psumsize][psumsize];

int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	int m,n,k;
	cin>>m>>n>>k;
	{
		for(int i=0;i<psumsize;i++){
			psum_J[i][0]=0;
			psum_J[0][i]=0;
			psum_O[i][0]=0;
			psum_O[0][i]=0;
			psum_I[i][0]=0;
			psum_I[0][i]=0;
		}

		string s;
		for(int i=1;i<=m;i++){
			cin>>s;
			for(int j=1;j<=n;j++){
				switch(s[j-1]){
					case 'J':
						psum_J[i][j]=1;
						break;
					case 'O':
						psum_O[i][j]=1;
						break;
					case 'I':
						psum_I[i][j]=1;
						break;
				}
				psum_J[i][j]+=psum_J[i][j-1];
				psum_O[i][j]+=psum_O[i][j-1];
				psum_I[i][j]+=psum_I[i][j-1];
			}
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				psum_J[i][j]+=psum_J[i-1][j];
				psum_O[i][j]+=psum_O[i-1][j];
				psum_I[i][j]+=psum_I[i-1][j];
			}
		}
	}

	int a,b,c,d;

	for(int i=0;i<k;i++){
		cin>>a>>b>>c>>d;
		a--;b--;
		cout
			<<psum_J[c][d]-psum_J[a][d]-psum_J[c][b]+psum_J[a][b]
			<<' '
			<<psum_O[c][d]-psum_O[a][d]-psum_O[c][b]+psum_O[a][b]
			<<' '
			<<psum_I[c][d]-psum_I[a][d]-psum_I[c][b]+psum_I[a][b]
			<<en;
	}


	return 0;
}