import sys
def input(): return sys.stdin.readline().strip()

m,n=map(int,input().split())
k=int(input())

joi=dict()
joi["J"]=0
joi["O"]=1
joi["I"]=2


mnj=[[0]*(n+1) for i in range(m+1)]
mno=[[0]*(n+1) for i in range(m+1)]
mni=[[0]*(n+1) for i in range(m+1)]
for i in range(1,m+1):
    mns=input()
    mnii=[0]*3
    for ii in range(1,n+1):
        mnii[joi[mns[ii-1]]]+=1
        mnj[i][ii]=mnj[i-1][ii]+mnii[0]
        mno[i][ii]=mno[i-1][ii]+mnii[1]
        mni[i][ii]=mni[i-1][ii]+mnii[2]
    
s=[0]*3
for j in range(k):
    aj,bj,cj,dj=map(int,input().split())
    aj-=1
    bj-=1
    sj=mnj[cj][dj]-mnj[aj][dj]-mnj[cj][bj]+mnj[aj][bj]
    so=mno[cj][dj]-mno[aj][dj]-mno[cj][bj]+mno[aj][bj]
    si=mni[cj][dj]-mni[aj][dj]-mni[cj][bj]+mni[aj][bj]
    print(sj,so,si)
