#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))
#define PI 3.14159265358979


int main()
{
	int m,n;
	int k;
	int i,j,l;
	int half_m,half_n;
	scanf("%d %d",&m,&n);
	scanf("%d",&k);
	half_m = (m%2)?m/2+1:m/2;
	half_n = (n%2)?n/2+1:n/2;
	char** list = mem(char*,m);
	int** data = mem(char*,half_m);
	for(i = 0;i < m;i++)
	{
		list[i] = mem(char,n+1);
		scanf("%s",list[i]);
	}
	for(i = 0;i < half_m;i++)
	{
		data[i] = mem(int,half_n);
		for(j = 0;j < half_n;j++)
		{
			switch(list[i*2][j*2])
			{
				case 'J':
					data[i][j] += 1;
					break;
				case 'O':
					data[i][j] += 8;
					break;
			}
			switch(list[i*2+1][j*2])
			{
				case 'J':
					data[i][j] += 1;
					break;
				case 'O':
					data[i][j] += 8;
					break;
			}
			switch(list[i*2][j*2+1])
			{
				case 'J':
					data[i][j] += 1;
					break;
				case 'O':
					data[i][j] += 8;
					break;
			}
			switch(list[i*2+1][j*2+1])
			{
				case 'J':
					data[i][j] += 1;
					break;
				case 'O':
					data[i][j] += 8;
					break;
			}
		} 
	}
	for(i = 0;i < k;i++)
	{
		int a,b,c,d;
		int count[2] = {0,0};
		scanf("%d %d %d %d",&a,&b,&c,&d);
		if(a & 1)
		{
			for(j = b-1;j < d;j++)
			{
				if(list[a-1][j] == 'J')
					count[0]++;
				else if(list[a-1][j] == 'O')
					count[1]++;
			}
			if(b & 1)
			{
				for(j = a;j < c;j++)
				{
					if(list[j][b-1] == 'J')
						count[0]++;
					else if(list[j][b-1] == 'O')
						count[1]++;
				}
				b++;
			}
			a++;
		}
		else if(b & 1)
		{
			for(j = a-1;j < c;j++)
			{
				if(list[j][b-1] == 'J')
					count[0]++;
				else if(list[j][b-1] == 'O')
					count[1]++;
			}
			b++;
		}
		for(j = a/2-1;j < c/2;j++)
		{
			for(l = b/2-1;l < d/2;l++)
			{
				if(list[j][l] == 'J')
					count[0]++;
				else if(list[j][l] == 'O')
					count[1]++;
			}
		}
		if(c & 1)
		{
			for(j = b-1;j < d;j++)
			{
				if(list[c-1][j] == 'J')
					count[0]++;
				else if(list[c-1][j] == 'O')
					count[1]++;
			}
			if(d & 1)
			{
				for(j = a;j < c;j++)
				{
					if(list[j][d-1] == 'J')
						count[0]++;
					else if(list[j][d-1] == 'O')
						count[1]++;
				}
				b++;
			}
			a++;
		}
		else if(d & 1)
		{
			for(j = a-1;j < c;j++)
			{
				if(list[j][d-1] == 'J')
					count[0]++;
				else if(list[j][d-1] == 'O')
					count[1]++;
			}
			b++;
		}
		printf("%d %d %d\n",count[0],count[1],(c-a+1)*(d-b+1)-count[0]-count[1]);
	}
	return 0;
}