# use dp
# python 3.

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

# answer matrix
dp_j = [[0 for i in range(n+1)]for j in range(m+1)]
dp_o = [[0 for i in range(n+1)]for j in range(m+1)]


# input row and calc dp
for i in range(1, m+1):
   row = list(input())
   # print(row)
   for j in range(1, n+1):
      dp_j[i][j] = dp_j[i-1][j] + dp_j[i][j-1] - dp_j[i-1][j-1] + (1 if row[j-1] == 'J' else 0)
      dp_o[i][j] = dp_o[i-1][j] + dp_o[i][j-1] - dp_o[i-1][j-1] + (1 if row[j-1] == 'O' else 0) 

      
for i in range(k):
   a, b, c, d = map(int, input().split())

   j_cnt = dp_j[c][d] - dp_j[a-1][d] - dp_j[c][b-1] + dp_j[a-1][b-1]
   o_cnt = dp_o[c][d] - dp_o[a-1][d] - dp_o[c][b-1] + dp_o[a-1][b-1]
   i_cnt = (abs(c-a)+1) *  (abs(d-b)+1) - j_cnt - o_cnt

   print(str(j_cnt) + ' ' + str(o_cnt) + ' ' + str(i_cnt))