#include <bits/stdc++.h>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

int J[1010][1010], O[1010][1010], I[1010][1010];

signed main()
{
    int M, N; cin >> M >> N;
    int K; cin >> K;

    rep(i, M) rep(j, N) {
        char C; cin >> C;

        if (C == 'J') J[i+1][j+1]++;
        if (C == 'O') O[i+1][j+1]++;
        if (C == 'I') I[i+1][j+1]++;
    }

    for (int i = 1; i <= 1000; ++i) {
        for (int j = 1; j <= 1000; ++j) {
            J[i][j] += J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
            O[i][j] += O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
            I[i][j] += I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];
        }
    }

    rep(_, K) {
        int a, b, c, d; cin >> a >> b >> c >> d;

        int j = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
        int o = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
        int i = I[c][d] - I[a - 1][d] - I[c][b - 1] + I[a - 1][b - 1];

        cout << j << ' ' << o << ' ' << i << endl;
    }
}