#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
using ll = i64;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using matrix = vector<vector<T> >;
template <class T>
inline string toString(const vector<T>& x) {
  stringstream ss;
  for (int i = 0; i < (int)(x.size()); ++i) {
    if (i != 0) ss << " ";
    ss << x[i];
  }
  return ss.str();
}
template <class T>
inline string toString(const vector<vector<T> >& map) {
  stringstream ss;
  for (int i = 0; i < (int)(map.size()); ++i) {
    if (i != 0) ss << "\n";
    ss << toString(map[i]);
  }
  return ss.str();
}
template <class K, class V>
string toString(map<K, V>& x) {
  string res;
  stringstream ss;
  for (auto& p : x) ss << p.first << ":" << p.second << " ";
  return ss.str();
}
string BITtoString(int bit) {
  stringstream ss;
  while (bit != 0) {
    ss << (bit % 2);
    bit /= 2;
  }
  string res = ss.str();
  reverse((res).begin(), (res).end());
  return res;
}
template <typename T, typename V>
inline T mod(T v, V MOD) {
  return (v % MOD + MOD) % MOD;
}
namespace Fenwicks {
template <typename T>
class Fenwick {
 public:
  int size;
  vector<T> bit;
  Fenwick() : Fenwick(0) {}
  Fenwick(int n) : size(n) { bit = vector<T>(n + 1); }
  T sum(int n) {
    T s = 0;
    while (n > 0) {
      s += bit[n];
      n -= n & -n;
    }
    return s;
  }
  void add(int i, T x) {
    i++;
    while (i <= size) {
      bit[i] += x;
      i += i & -i;
    }
  }
  T sum(int a, int b) { return sum(b) - sum(a); }
};
template <typename T>
class Fenwick2D {
 public:
  int H, W;
  vector<Fenwick<T> > fs;
  Fenwick2D() : Fenwick2D(0, 0) {}
  Fenwick2D(int H, int W) : H(H), W(W) {
    fs = vector<Fenwick<T> >(H + 1, Fenwick<T>(W));
  }
  T sum(int y, int x) {
    T s = 0;
    while (y > 0) {
      s += fs[y].sum(x);
      y -= y & -y;
    }
    return s;
  }
  void add(int y, int x, T v) {
    y++;
    while (y <= H) {
      fs[y].add(x, v);
      y += y & -y;
    }
  }
  T sum(int y1, int x1, int y2, int x2) {
    return sum(y2, x2) - sum(y2, x1) - sum(y1, x2) + sum(y1, x1);
  }
};
}  // namespace Fenwicks
using namespace Fenwicks;
class Main {
 public:
  void run() {
    int H, W;
    cin >> H >> W;
    int Q;
    cin >> Q;
    vector<string> board(H);
    for (int y = 0; y < (int)(H); ++y) cin >> board[y];
    Fenwick2D<int> J(H, W), O(H, W), I(H, W);
    for (int y = 0; y < (int)(H); ++y)
      for (int x = 0; x < (int)(W); ++x) {
        if (board[y][x] == 'J') J.add(y, x, 1);
        if (board[y][x] == 'O') O.add(y, x, 1);
        if (board[y][x] == 'I') I.add(y, x, 1);
      }
    for (int q = 0; q < (int)(Q); ++q) {
      int y1, x1, y2, x2;
      cin >> y1 >> x1 >> y2 >> x2;
      y1--;
      x1--;
      y2--;
      x2--;
      cout << J.sum(y1, x1, y2 + 1, x2 + 1) << " "
           << O.sum(y1, x1, y2 + 1, x2 + 1) << " "
           << I.sum(y1, x1, y2 + 1, x2 + 1) << endl;
    }
  }
};
int main() {
  Main().run();
  return 0;
}
