#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<vector<int> > > n(h+1, vector<vector<int> >(w+1, vector<int>(3, 0)));
    for(int y=1; y<=h; ++y){
        vector<int> row(3, 0);
        for(int x=1; x<=w; ++x){
            char c;
            cin >> c;

            if(c == 'J')
                ++ row[0];
            else if(c == 'O')
                ++ row[1];
            else
                ++ row[2];

            for(int i=0; i<3; ++i)
                n[y][x][i] = n[y-1][x][i] + row[i];
        }
    }

    while(--k >= 0){
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;

        for(int i=0; i<3; ++i){
            int ret = n[y2][x2][i] - n[y2][x1-1][i] - n[y1-1][x2][i] + n[y1-1][x1-1][i];
            cout << ret;
            if(i < 2)
                cout << ' ';
            else
                cout << endl;
        }
    }

    return 0;
}