M, N = map(int, input().split())
K = int(input())
P = ['_' * (N + 1) for _ in range(M + 1)]
for mi in range(1, M + 1):
    P[mi] = '_' + input()
# for p in P:
#     print('p', p)

J = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
O = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
I = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
for i in range(1, M + 1):
    ji, oi, ii = 0, 0, 0
    for j in range(1, N + 1):
        ji += P[i][j] == 'J'
        oi += P[i][j] == 'O'
        ii += P[i][j] == 'I'
        J[i][j] = J[i - 1][j] + ji
        O[i][j] = O[i - 1][j] + oi
        I[i][j] = I[i - 1][j] + ii
# for j in J:
#     print('j', j)
# for o in O:
#     print('o', o)
# for i in I:
#     print('i', i)


def cum(mat, a, b, c, d):
    a -= 1
    b -= 1
    return mat[a][b] + mat[c][d] - mat[a][d] - mat[c][b]

for k in range(K):
    a, b, c, d = map(int, input().split())
    j = cum(J, a, b, c, d)
    o = cum(O, a, b, c, d)
    i = cum(I, a, b, c, d)
    print(j, o, i)