import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int M, N, K;
    scanf("%d %d\n%d\n", &M, &N, &K);
    auto F = new int[][][](M, N + 1, 3);
    foreach (p; 0 .. M) {
        string l = readln.chomp;
        int j, o, i;
        foreach (q, c; l) {
            F[p][q][0] = j;
            F[p][q][1] = o;
            F[p][q][2] = i;
            switch (c) {
                case 'J': j++; break;
                case 'O': o++; break;
                case 'I': i++; break;
                default: assert(0);
            }
        }
        auto r = l.length;
        F[p][r][0] = j;
        F[p][r][1] = o;
        F[p][r][2] = i;
    }
    foreach (_; 0 .. K) {
        int a, b, c, d;
        scanf("%d %d %d %d\n", &a, &b, &c, &d);
        a--; b--; c--; d--;
        auto ans = new int[3];
        for (auto i = a; i <= c; i++) {
            for (auto k = 0; k < 3; k++) {
                ans[k] += F[i][d + 1][k] - F[i][b][k];
            }
        }
        write(ans[0]);
        foreach (i; 1 .. 3) write(" ", ans[i]);
        writeln;
    }
}