#include <bits/stdc++.h>
enum class Land {
  J,
  O,
  I,
};
using mat2 = std::vector<std::vector<Land>>;
std::tuple<int, int, int> assess(mat2 const &l, int a, int b, int c, int d);
int main(void) {
  int M, N, K;
  std::cin >> M >> N >> K;
  mat2 l;
  l.resize(M);
  for (auto &x : l) {
    x.resize(N);
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      char tmp;
      std::cin >> tmp;
      switch (tmp) {
        case 'J':
          l[i][j] = Land::J;
          break;
        case 'O':
          l[i][j] = Land::O;
          break;
        case 'I':
          l[i][j] = Land::I;
          break;
      }
    }
  }
  for (int k = 0; k < K; k++) {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    auto s = assess(l, a - 1, b - 1, c - 1, d - 1);
    std::cout << std::get<0>(s) << " " << std::get<1>(s) << " "
              << std::get<2>(s) << std::endl;
  }
  return 0;
}
std::tuple<int, int, int> assess(mat2 const &l, int a, int b, int c, int d) {
  int J = 0, O = 0, I = 0;
  for (int i = a; i <= c; i++) {
    for (int j = b; j <= d; j++) {
      switch (l[i][j]) {
        case Land::J:
          J++;
          break;
        case Land::O:
          O++;
          break;
        case Land::I:
          I++;
          break;
      }
    }
  }
  return std::make_tuple(J, O, I);
}
