#include <bits/stdc++.h>
using namespace std;
template <typename T>
class BIT {
 private:
  int n, m;
  vector<vector<T> > bit;

 public:
  void add(int i, int j, T val) {
    for (int i_ = i + 1; i_ < n; i_ += i_ & -i_)
      for (int j_ = j + 1; j_ < m; j_ += j_ & -j_) bit[i_][j_] += val;
  }
  T sum(int i, int j) {
    T s = 0;
    for (int i_ = i + 1; i_ > 0; i_ -= i_ & -i_)
      for (int j_ = j + 1; j_ > 0; j_ -= j_ & -j_) s += bit[i_][j_];
    return s;
  }
  T sum(int lx, int rx, int ly, int ry) {
    return sum(rx - 1, ry - 1) - sum(lx - 1, ry - 1) - sum(rx - 1, ly - 1) +
           sum(lx - 1, ly - 1);
  }
  BIT(int sz1, int sz2) {
    n = sz1 + 1, m = sz2 + 1;
    bit.resize(n, vector<T>(m, 0));
  }
  BIT(vector<vector<T> >& v) {
    n = (int)v.size() + 1, m = (int)v[0].size() + 1;
    bit.resize(n, vector<T>(m, 0));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) add(i, j, v[i][j]);
  }
  void print_sum() {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cout << sum(i - 1, j - 1) << " ";
    cout << "\n";
  }
};
int main() {
  int m, n, K;
  cin >> m >> n >> K;
  vector<BIT<int> > bt(3, BIT<int>(m, n));
  vector<string> s(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    for (int j = 0; j < n; j++) {
      if (s[i][j] == 'J') {
        bt[0].add(i, j, 1);
      } else if (s[i][j] == 'O') {
        bt[1].add(i, j, 1);
      } else {
        bt[2].add(i, j, 1);
      }
    }
  }
  for (int i = 0; i < K; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;
    cout << bt[0].sum(a, b, c, d) << " " << bt[1].sum(a, b, c, d) << " "
         << bt[2].sum(a, b, c, d) << "\n";
  }
  return 0;
}
