#include <cstdio>

int joi2num(char c)
{
if(c == 'J') return 0;
if(c == 'O') return 1;
return 2;
}

int main()
{
int m, n, k;
static char fld[1024][1024];
static int sum[1024][1024][3] = {0};
scanf("%d%d%d", &m, &n, &k);
for(int x = 0; x < m; ++x)
scanf("%s", fld[x]);
for(int i = 0; i < 3; ++i)
sum[0][0][i] = (i == joi2num(fld[0][0]));
for(int x = 1; x < m; ++x) {
for(int i = 0; i < 3; ++i)
sum[x][0][i] = sum[x - 1][0][i] + (i == joi2num(fld[x][0]));
}
for(int y = 1; y < n; ++y) {
for(int i = 0; i < 3; ++i)
sum[0][y][i] = sum[0][y - 1][i] + (i == joi2num(fld[0][y]));
}
for(int x = 1; x < m; ++x) {
for(int y = 1; y < n; ++y) {
for(int i = 0; i < 3; ++i) {
int temp = 0;
temp += sum[x - 1][y][i];
temp += sum[x][y - 1][i];
temp -= sum[x - 1][y - 1][i];
sum[x][y][i] = temp + (i == joi2num(fld[x][y]));
}
}
}
for(int i = 0; i < k; ++i) {
int ax, ay, bx, by;
scanf("%d%d%d%d", &ax, &ay, &bx, &by);
ax -= 1, ay -= 1, bx -= 1, by -= 1;
int ans[3] = {0};
for(int  j = 0; j < 3; ++j) {
ans[j] += sum[bx][by][j];
ans[j] -= ax > 0 ? sum[ax - 1][by][j] : 0;
ans[j] -= ay > 0 ? sum[bx][ay - 1][j] : 0;
ans[j] += ax > 0 && ay > 0 ? sum[ax - 1][ay - 1][j] : 0;
}
printf("%d %d %d\n", ans[0], ans[1], ans[2]);
}
return 0;
}