N,M=map(int,raw_input().split())
K=int(raw_input())
A=[]
B=[ [[0,0,0] for j in range(M+1)] for i in range(N+1)]
for i in range(N):
    A.append(raw_input())
for i in range(1,N+1):
    for j in range(1,M+1):
        c=A[i-1][j-1]
        B[i][j][0]=B[i-1][j][0]+B[i][j-1][0]-B[i-1][j-1][0]+(c=='J')
        B[i][j][1]=B[i-1][j][1]+B[i][j-1][1]-B[i-1][j-1][1]+(c=='O')
        B[i][j][2]=B[i-1][j][2]+B[i][j-1][2]-B[i-1][j-1][2]+(c=='I')
for k in range(K):
    a,b,c,d=map(int,raw_input().split())
    aj=B[c][d][0]-B[c][b-1][0]-B[a-1][d][0]+B[a-1][b-1][0]
    ao=B[c][d][1]-B[c][b-1][1]-B[a-1][d][1]+B[a-1][b-1][1]
    ai=B[c][d][2]-B[c][b-1][2]-B[a-1][d][2]+B[a-1][b-1][2]
    print aj,ao,ai
    