#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 1e5;

int main() {
    int M, N, K;
    cin >> M >> N >> K;
    vector<string> v(M);
    for(int i=0; i<M; ++i) {
        cin >> v[i];
    }
    vector<vector<int>> J(M+1, vector<int>(N+1)), O(M+1, vector<int>(N+1));
    for(int i=0; i<M; ++i) {
        for(int j=0; j<N; ++j) {
            J[i+1][j+1] = v[i][j] == 'J';
            O[i+1][j+1] = v[i][j] == 'O';
        }
    }
    for(int i=0; i<M+1; ++i) {
        for(int j=0; j<N; ++j) {
            J[i][j+1] += J[i][j];
            O[i][j+1] += O[i][j];
        }
    }
    for(int j=0; j<N+1; ++j) {
        for(int i=0; i<M; ++i) {
            J[i+1][j] += J[i][j];
            O[i+1][j] += O[i][j];
        }
    }
    for(int i=0; i<K; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int res_j = J[c][d] - J[a-1][d] - J[c][b-1] + J[a-1][b-1];
        int res_o = O[c][d] - O[a-1][d] - O[c][b-1] + O[a-1][b-1];
        int res_i = (c - a + 1) * (d - b + 1) - res_j - res_o;
        cout << res_j << ' ' << res_o << ' ' << res_i << endl;
    }
}