#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& a) {
  return is >> a.first >> a.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& a) {
  return os << a.first << " " << a.second;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vc) {
  for (int i = 0; i < vc.size(); i++) is >> vc[i];
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vc) {
  for (int i = 0; i < vc.size(); i++) os << vc[i] << endl;
  return os;
}
int M, N, K, sum[3][1000][1000] = {{{}}};
string temp = "JOI";
int main() {
  cin >> M >> N;
  cin >> K;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      char c;
      cin >> c;
      for (int k = 0; k < 3; k++) {
        if (temp[k] == c) ++sum[k][i][j];
        sum[k][i][j] +=
            sum[k][i - 1][j] + sum[k][i][j - 1] - sum[k][i - 1][j - 1];
      }
    }
  }
  for (int k = 0; k < 3; k++) {
    for (int i = 1; i <= M; i++) {
      for (int j = 1; j <= N; j++) {
        printf("%3d", sum[k][i][j]);
      }
      printf("\n");
    }
    puts("");
  }
  while (K--) {
    int ax, by, cx, dy;
    cin >> ax >> by >> cx >> dy;
    swap(ax, by), swap(cx, dy);
    for (int i = 0; i < 3; i++) {
      int hoge = sum[i][dy][cx] + sum[i][by - 1][ax - 1] - sum[i][dy][ax - 1] -
                 sum[i][by - 1][cx];
      cout << (i == 0 ? "" : " ") << hoge;
    }
    cout << endl;
  }
}
