#include <bits/stdc++.h>
int main(void) {
  int i, j, k, l, m, n;
  int aa, bb, cc, dd;
  int jj, ii, oo;
  char t;
  char temp[101];
  char a[101][101];
  int J[101][101];
  int I[101][101];
  int O[101][101];
  scanf("%d %d", &i, &j);
  scanf("%d", &k);
  for (l = 0; l < i; l++) {
    scanf("%s", temp);
    for (m = 0; m < j; m++) {
      a[l][m] = temp[m];
    }
  }
  n = 1;
  for (l = 0; l < j; l++) {
    if (a[0][l] == 'J') {
      J[0][l] = n;
      n++;
    } else {
      if (l - 1 < 0) {
        J[0][l] = 0;
      } else {
        J[0][l] = J[0][l - 1];
      }
    }
  }
  for (l = 1; l < i; l++) {
    for (m = 0; m < j; m++) {
      if (m == 0) {
        J[l][0] = J[l - 1][0];
        if (a[l][0] == 'J') {
          J[l][0] = J[l][0] + 1;
        }
      } else {
        J[l][m] = J[l - 1][m] + J[l][m - 1] - J[l - 1][m - 1];
        if (a[l][m] == 'J') {
          J[l][m] = J[l][m] + 1;
        }
      }
    }
  }
  n = 1;
  for (l = 0; l < j; l++) {
    if (a[0][l] == 'O') {
      O[0][l] = n;
      n++;
    } else {
      if (l - 1 < 0) {
        O[0][l] = 0;
      } else {
        O[0][l] = O[0][l - 1];
      }
    }
  }
  for (l = 1; l < i; l++) {
    for (m = 0; m < j; m++) {
      if (m == 0) {
        O[l][0] = O[l - 1][0];
        if (a[l][0] == 'O') {
          O[l][0] = O[l][0] + 1;
        }
      } else {
        O[l][m] = O[l - 1][m] + O[l][m - 1] - O[l - 1][m - 1];
        if (a[l][m] == 'O') {
          O[l][m] = O[l][m] + 1;
        }
      }
    }
  }
  n = 1;
  for (l = 0; l < j; l++) {
    if (a[0][l] == 'I') {
      I[0][l] = n;
      n++;
    } else {
      if (l - 1 < 0) {
        I[0][l] = 0;
      } else {
        I[0][l] = I[0][l - 1];
      }
    }
  }
  for (l = 1; l < i; l++) {
    for (m = 0; m < j; m++) {
      if (m == 0) {
        I[l][0] = I[l - 1][0];
        if (a[l][0] == 'I') {
          I[l][0] = I[l][0] + 1;
        }
      } else {
        I[l][m] = I[l - 1][m] + I[l][m - 1] - I[l - 1][m - 1];
        if (a[l][m] == 'I') {
          I[l][m] = I[l][m] + 1;
        }
      }
    }
  }
  for (l = 0; l < k; l++) {
    scanf("%d %d %d %d", &aa, &bb, &cc, &dd);
    aa = aa - 1;
    bb = bb - 1;
    cc = cc - 1;
    dd = dd - 1;
    if (aa == 0) {
      if (bb == 0) {
        jj = J[cc][dd];
        ii = I[cc][dd];
        oo = O[cc][dd];
      } else {
        jj = J[cc][dd] - J[cc][bb - 1];
        ii = I[cc][dd] - I[cc][bb - 1];
        oo = O[cc][dd] - O[cc][bb - 1];
      }
    } else {
      jj = J[cc][dd] - J[aa - 1][dd] - J[cc][bb - 1] + J[aa - 1][bb - 1];
      ii = I[cc][dd] - I[aa - 1][dd] - I[cc][bb - 1] + I[aa - 1][bb - 1];
      oo = O[cc][dd] - O[aa - 1][dd] - O[cc][bb - 1] + O[aa - 1][bb - 1];
    }
    printf("%d %d %d\n", jj, oo, ii);
  }
  return 0;
}
