#include <bits/stdc++.h>
using namespace std;
int Y[2][1000000], X[2][1000000];
int TOP[2];
char m[2] = {'J', 'O'};
int E[2][1001];
int main() {
  int h, w, q;
  char z;
  cin >> h >> w >> q;
  TOP[0] = 0, TOP[1] = 0;
  E[0][0] = 0, E[1][0] = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> z;
      for (int k = 0; k < 2; k++) {
        if (m[k] == z) {
          Y[k][TOP[k]] = i;
          X[k][TOP[k]] = j;
          TOP[k]++;
        }
      }
    }
    E[0][i + 1] = TOP[0];
    E[1][i + 1] = TOP[1];
  }
  int x[2], y[2];
  for (int u = 0; u < q; u++) {
    for (int i = 0; i < 2; i++) {
      cin >> y[i] >> x[i];
      y[i]--, x[i]--;
    }
    int cnt = (x[1] - x[0] + 1) * (y[1] - y[0] + 1);
    for (int v = 0; v < 2; v++) {
      int ans = 0;
      for (int i = y[0]; i <= y[1]; i++) {
        int left, right, midl, midr;
        left = E[v][i], right = E[v][i + 1];
        bool end = false;
        while (true) {
          if (left >= right - 1) break;
          midl = (left + right) / 2;
          if (X[v][midl] == x[0]) break;
          if (X[v][midl] < x[0])
            left = midl;
          else
            right = midl;
        }
        midl--;
        if (X[v][midl] < x[0]) midl++;
        left = E[v][i], right = E[v][i + 1];
        end = false;
        while (true) {
          if (left >= right - 1) break;
          midr = (left + right) / 2;
          if (X[v][midr] == x[1] + 1) break;
          if (X[v][midr] < x[1] + 1)
            left = midr;
          else
            right = midr;
        }
        if (X[v][midr] <= x[1]) midr++;
        if (midr > 0)
          if (Y[v][midr - 1] == Y[v][midr] && X[v][midr - 1] > x[1]) midr--;
        ans += midr - midl;
      }
      cnt -= ans;
      cout << ans << " ";
    }
    cout << cnt << endl;
  }
  return 0;
}
