#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int a[1001][1001][3];
//3つ目の要素：0 = Jungle, 1 = Ocean, 2 = Ice

int main()
{
	int m, n, k;

	cin >> m >> n;
	cin >> k;
	memset(a, 0, sizeof(a));

	string str;

	for (int i = 1; i <= m; i++)
	{
		cin >> str;
		for (int j = 1; j <= n; j++)
		{
			for (int l = 0; l < 3; l++)
			{
				a[i][j][l] = a[i - 1][j][l] + a[i][j - 1][l] - a[i - 1][j - 1][l];
			}
			switch (str[j - 1])
			{
				case 'J':
					a[i][j][0]++;
					break;

				case 'O':
					a[i][j][1]++;
					break;

				case 'I':
					a[i][j][2]++;
					break;

				default:
					break;
			}
		}
	}

	for (int i = 0; i < k; i++)
	{
		int startx, starty, endx, endy;
		cin >> startx >> starty >> endx >> endy;
		
		for (int j = 0; j < 3; j++)
		{
			cout << a[endx][endy][j] - a[endx][starty - 1][j] - a[startx - 1][endy][j] + a[startx - 1][starty - 1][j];
			if (j != 2)
			{
				cout << " ";
			}
			else
			{
				cout << endl;
			}
		}
	}
	return 0;
}