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;

struct JOI {
    int j, o, i;
    JOI opBinary(string op)(const ref JOI joi) const {
        static if (op == "+") {
            return JOI(j + joi.j, o + joi.o, i + joi.i);
        } else static if (op == "-") {
            return JOI(j - joi.j, o - joi.o, i - joi.i);
        }
        assert(0);
    }
}

void main() {
    int M, N, K;
    scanf("%d %d\n%d\n", &M, &N, &K);
    auto F = new string[M];
    foreach (p; 0 .. M) F[p] = readln.chomp;
    auto T = new JOI[][](M + 1, N + 1);
    foreach (p; 0 .. M) {
        JOI x;
        foreach (q; 0 .. N) {
            char c = F[p][q];
            switch (c) {
                case 'J': x.j++; break;
                case 'O': x.o++; break;
                case 'I': x.i++; break;
                default: assert(0);
            }
            T[p + 1][q + 1] = T[p][q + 1] + x;
        }
    }
    //foreach (ref _; T) _.writeln;
    foreach (_; 0 .. K) {
        int a, b, c, d;
        scanf("%d %d %d %d\n", &a, &b, &c, &d);
        a--; b--;
        JOI ans = T[c][d] - T[c][b] - T[a][d] + T[a][b];
        writeln(ans.j, " ", ans.o, " ", ans.i);
    }
}