#include <bits/stdc++.h>
using namespace std;
pair<int, int> J[1000001];
pair<int, int> O[1000001];
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  char z;
  int jtop = 0, otop = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> z;
      if (z == 'J') {
        J[jtop].first = i;
        J[jtop].second = j;
        jtop++;
      }
      if (z == 'O') {
        O[otop].first = i;
        O[otop].second = j;
        otop++;
      }
    }
  }
  int x[2], y[2];
  for (int u = 0; u < k; u++) {
    for (int i = 0; i < 2; i++) {
      cin >> y[i] >> x[i];
      y[i]--;
      x[i]--;
    }
    int left = 0, right = jtop, midl;
    while (true) {
      if (left >= right - 1) break;
      midl = (right + left) / 2;
      if (J[midl].first < y[0])
        left = midl;
      else
        right = midl;
    }
    left = 0, right = jtop;
    int midr;
    while (true) {
      if (left >= right - 1) break;
      midr = (right + left) / 2;
      if (J[midr].first <= y[1])
        left = midr;
      else
        right = midr;
    }
    if (midr == jtop - 1) midr++;
    int jans = 0;
    for (int i = max(0, midl - 1); i <= min(midr + 1, jtop - 1); i++) {
      if (J[i].second >= x[0] && J[i].second <= x[1]) {
        if (J[i].first >= y[0] && J[i].first <= y[1]) jans++;
      }
    }
    left = 0, right = otop;
    while (true) {
      if (left >= right - 1) break;
      midl = (right + left) / 2;
      if (O[midl].first < y[0])
        left = midl;
      else
        right = midl;
    }
    left = 0, right = otop;
    while (true) {
      if (left >= right - 1) break;
      midr = (right + left) / 2;
      if (O[midr].first <= y[1])
        left = midr;
      else
        right = midr;
    }
    if (midr == otop - 1) midr++;
    int oans = 0;
    for (int i = max(midl - 1, 0); i <= min(midr + 1, otop - 1); i++) {
      if (O[i].second >= x[0] && O[i].second <= x[1]) {
        if (O[i].first >= y[0] && O[i].first <= y[1]) oans++;
      }
    }
    int s = (x[1] - x[0] + 1) * (y[1] - y[0] + 1);
    cout << jans << " " << oans << " " << s - jans - oans << endl;
  }
  return 0;
}
