import std.stdio;
import std.string;
import std.conv;

enum TYPE {
    JUNGLE,
    OCEAN,
    ICE
}

struct Point {
    int x;
    int y;
}

struct Rect {
    Point start;
    Point end;
}

void main() {
    
    // input
    int m, n, k;
    {
        auto temp = readln.split;
        m = to!int(temp[0]);
        n = to!int(temp[1]);
    }
    k = to!int(readln.chomp);
    
    int[][] field;
    field.length = m;
    for(int i=0; i<m; ++i) {
        field[i].length = n;
    }
    
    for(int i=0; i<m; ++i) {
        auto str = readln.chomp;
        for(int j=0; j<n; ++j) {
            final switch(str[j]) {
                case 'J':
                    field[i][j] = TYPE.JUNGLE;
                    break;
                
                case 'O':
                    field[i][j] = TYPE.OCEAN;
                    break;
                
                case 'I':
                    field[i][j] = TYPE.ICE;
                    break;
            }
        }
    }
    
    Rect[] r;
    r.length = k;
    
    for(int i=0; i<k; ++i) {
        auto temp = readln.split;
        r[i].start.x = to!int(temp[0]) -1;
        r[i].start.y = to!int(temp[1]) -1;
        r[i].end.x = to!int(temp[2]) -1;
        r[i].end.y = to!int(temp[3]) -1;
    }
    
    // calc
    for(int i=0; i<k; ++i) {
        int jungle, ocean, ice;
        for(int x=r[i].start.x; x<=r[i].end.x; ++x) {
            for(int y=r[i].start.y; y<=r[i].end.y; ++y) {
                
                final switch(field[x][y]) {
                    case TYPE.JUNGLE:
                        ++jungle;
                        break;
                    
                    case TYPE.OCEAN:
                        ++ocean;
                        break;
                        
                    case TYPE.ICE:
                        ++ice;
                        break;
                }
                
                
            }
        }
        
        // output
        writefln("%d %d %d", jungle, ocean, ice);
    }
    
}