#include <bits/stdc++.h>
using namespace std;
int main() {
  int m;
  cin >> m;
  int n;
  cin >> n;
  int k;
  cin >> k;
  int a[m + 1][n + 1];
  int b[m + 1][n + 1];
  int c[m + 1][n + 1];
  int j;
  int o;
  int i;
  char d;
  int e;
  int f;
  e = 0;
  while (e < n + 1) {
    a[0][e] = 0;
    b[0][e] = 0;
    c[0][e] = 0;
    e = e + 1;
  }
  e = 0;
  while (e < m + 1) {
    a[e][0] = 0;
    b[e][0] = 0;
    c[e][0] = 0;
    e = e + 1;
  }
  f = 1;
  while (f < m + 1) {
    e = 1;
    j = 0;
    o = 0;
    i = 0;
    while (e < n + 1) {
      cin >> d;
      if (d == 'J') {
        j = j + 1;
      }
      if (d == 'O') {
        o = o + 1;
      }
      if (d == 'I') {
        i = i + 1;
      }
      a[f][e] = a[f - 1][e] + j;
      b[f][e] = b[f - 1][e] + o;
      c[f][e] = c[f - 1][e] + i;
      e = e + 1;
    }
    f = f + 1;
  }
  int p;
  int q;
  int r;
  int s;
  int t;
  int u;
  int v;
  e = 0;
  while (e < k) {
    cin >> p;
    cin >> q;
    cin >> r;
    cin >> s;
    t = a[r][s] - a[r][q - 1] - a[p - 1][s] + a[p - 1][q - 1];
    u = b[r][s] - b[r][q - 1] - b[p - 1][s] + b[p - 1][q - 1];
    v = c[r][s] - c[r][q - 1] - c[p - 1][s] + c[p - 1][q - 1];
    cout << t << " " << u << " " << v << endl;
    e = e + 1;
  }
}
