#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int J[1005][1005] = {};
int O[1005][1005] = {};
int I[1005][1005] = {};
int tate, yoko;
int n;
int main()
{
	cin >> tate >> yoko;
	cin >> n;

	for (int i = 1; i <= tate; i++)
	{
		string hoge;
		cin >> hoge;
		for (int k = 1; k <= yoko; k++)
		{
			switch (hoge[k-1])
			{
			case'J':
				J[i][k]++;
				break;
			case'O':
				O[i][k]++;
				break;
			case'I':
				I[i][k]++;
				break;
			}
		}
		for (int k = 1; k <= yoko+1; k++)
		{
			J[i][k] += J[i][k - 1];
			O[i][k] += O[i][k - 1];
			I[i][k] += I[i][k - 1];
		}
		
	}

	while (n--)
	{
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int jun = 0, oce = 0, ice = 0;
		for (int i = x1; i <= x2; i++)
		{
			jun += J[i][y2] - J[i][y1-1];
			oce += O[i][y2] - O[i][y1 - 1];
			ice += I[i][y2] - I[i][y1 - 1];
		}
		cout << jun <<" "<<oce<<" "<<ice<< endl;
	}

}