#include <iostream>
using namespace std;

const int SIZE = 1000;
int c[SIZE+1][SIZE+1][3];

const char *JOI = "JOI";

int main() {
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < 3; j++) {
            c[i][0][j] = c[0][i][j] = 0;
        }
    }
    int m, n;
    while (cin >> m >> n) {
        int k;
        cin >> k;
        for (int i = 1; i <= m; i++) {
            string s;
            cin >> s;
            for (int j = 1; j <= n; j++) {
                for (int k = 0; k < 3; k++) {
                    c[i][j][k] = c[i][j-1][k] + c[i-1][j][k] - c[i-1][j-1][k] + (s[j-1] == JOI[k]);
                }
            }
        }
        for (int i = 0; i < k; i++) {
            int x[2], y[2];
            cin >> y[0] >> x[0] >> y[1] >> x[1];
            for (int j = 0; j < 3; j++) {
                if (j > 0) {
                    cout << " ";
                }
                cout << c[y[1]][x[1]][j] - c[y[1]][x[0]-1][j] - c[y[0]-1][x[1]][j] + c[y[0]-1][x[0]-1][j];
            }
            cout << endl;
        }
    }
}