#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
	string c = "JOI";
	map<char, int> mc;
	for (int i = 0; i < c.size(); ++i) mc[c[i]] = i;

 	int w, h; cin >> h >> w;
	int k; cin >> k;
	vector<string> m(h);
	for (int y = 0; y < h; ++y) {
		cin >> m[y];
	}

	vector< vector< vector<int> > > s(3, vector< vector<int> >(h+1, vector<int>(w+1, 0)));
	for (int i = 0; i < 3; ++i) {
		for (int y = 1; y <= h; ++y) {
			for (int x = 1; x <= w; ++x) {
				if (m[y-1][x-1] == c[i]) s[i][y][x] = 1;
			}
		}
		for (int y = 1; y <= h; ++y) {
			for (int x = 2; x <= w; ++x) {
				s[i][y][x] += s[i][y][x-1];
			}
		}
		for (int x = 1; x <= w; ++x) {
			for (int y = 2; y <= h; ++y) {
				s[i][y][x] += s[i][y-1][x];
			}
		}
	}

	for (int t = 0; t < k; ++t) {
		int x1, y1, x2, y2; cin >> y1 >> x1 >> y2 >> x2;
		for (int i = 0; i < 3; ++i) {
			if (i) cout << " ";
			cout << (s[i][y2][x2] + s[i][y1-1][x1-1] - s[i][y2][x1-1] - s[i][y1-1][x2]);
		}
		cout << endl;
	}
}