#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  int yotei;
  cin >> m >> n >> yotei;
  int x[m][n][3];
  string ch;
  int t;
  for (int i = 0; i < m; i++) {
    cin >> ch;
    for (int j = 0; j < n; j++) {
      if (ch[j] == 'J')
        t = 0;
      else if (ch[j] == 'O')
        t = 1;
      else if (ch[j] == 'I')
        t = 2;
      if (i == 0) {
        if (j == 0) {
          for (int k = 0; k < 3; k++) {
            if (k == t)
              x[i][j][k] = 1;
            else
              x[i][j][k] = 0;
          }
        } else {
          for (int k = 0; k < 3; k++) {
            if (k == t)
              x[i][j][k] = x[i][j - 1][k] + 1;
            else
              x[i][j][k] = x[i][j - 1][k];
          }
        }
      } else {
        if (j == 0) {
          for (int k = 0; k < 3; k++) {
            if (k == t)
              x[i][j][k] = x[i - 1][j][k] + 1;
            else
              x[i][j][k] = x[i - 1][j][k];
          }
        } else {
          for (int k = 0; k < 3; k++) {
            if (k == t)
              x[i][j][k] =
                  x[i][j - 1][k] + x[i - 1][j][k] - x[i - 1][j - 1][k] + 1;
            else
              x[i][j][k] = x[i][j - 1][k] + x[i - 1][j][k] - x[i - 1][j - 1][k];
          }
        }
      }
    }
  }
  int a, b, c, d, ans[3];
  for (int i = 0; i < yotei; i++) {
    cin >> a >> b >> c >> d;
    a -= 2;
    b -= 2;
    c--;
    d--;
    if (a == -1) {
      if (b == -1) {
        for (int k = 0; k < 3; k++) {
          ans[k] = x[c][d][k];
        }
      } else {
        for (int k = 0; k < 3; k++) {
          ans[k] = x[c][d][k] - x[c][b][k];
        }
      }
    } else {
      if (b == -1) {
        for (int k = 0; k < 3; k++) {
          ans[k] = x[c][d][k] - x[a][d][k];
        }
      } else {
        for (int k = 0; k < 3; k++) {
          ans[k] = x[c][d][k] - x[a][d][k] - x[c][b][k] + x[a][b][k];
        }
      }
    }
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
  }
}
