#include <bits/stdc++.h>
using namespace std;
int J[1200][1200], O[1200][1200], I[1200][1200];
int H, W, Q;
string S;
int main() {
  cin >> H >> W >> Q;
  for (int i = 1; i <= H; i++) {
    cin >> S;
    for (int j = 0; j < S.size(); j++) {
      if (S[j] == 'J') J[i][j + 1]++;
      if (S[j] == 'O') O[i][j + 1]++;
      if (S[j] == 'I') I[i][j + 1]++;
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) J[i][j] += J[i - 1][j];
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) J[i][j] += J[i][j - 1];
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) O[i][j] += O[i - 1][j];
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) O[i][j] += O[i][j - 1];
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) I[i][j] += I[i - 1][j];
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) I[i][j] += I[i][j - 1];
  }
  for (int i = 0; i < Q; i++) {
    int ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    ax--;
    ay--;
    int pos1 = J[ax][ay] + J[bx][by] - J[ax][by] - J[ay][bx];
    int pos2 = O[ax][ay] + O[bx][by] - O[ax][by] - O[ay][bx];
    int pos3 = I[ax][ay] + I[bx][by] - I[ax][by] - I[bx][ay];
    cout << pos1 << ' ' << pos2 << ' ' << pos3 << endl;
  }
  return 0;
}
