// AOJ 0560 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0560)
#include<cstdio>
#include<string>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_M = 1000, MAX_N = 1000;
const std::string JOI = "JOI";

int M, N, K;
int S[3][MAX_M+2][MAX_N+2];

int main()
{
	scanf( "%d%d%d", &M, &N, &K );
	rep( i, M )
	{
		getchar();

		rep( j, N )
			++S[JOI.find(getchar())][i+1][j+1];
	}

	rep( k, 3 ) rep( i, M ) rep( j, N )
		S[k][i+1][j+1] += S[k][i+1][j]+S[k][i][j+1]-S[k][i][j];

	rep( i, K )
	{
		int a, b, c, d;
		scanf( "%d%d%d%d", &a, &b, &c, &d );
		--a; --b;

		rep( k, 3 )
			printf( "%d%c", S[k][c][d]-S[k][c][b]-S[k][a][d]+S[k][a][b], k==2?'\n':' ' );
	}

	return 0;
}