#include <bits/stdc++.h>
using namespace std;
static const int INF = 1e9;
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline int make_mask(unsigned long long int upper,
                     unsigned long long int lower) {
  assert(lower < 64 && upper < 64 && lower <= upper);
  return ((assert((!numeric_limits<typeof(upper)>::is_signed)),
           assert(upper < 64), (1ULL << (upper))) -
          1) ^
         ((assert((!numeric_limits<typeof(lower)>::is_signed)),
           assert(lower < 64), (1ULL << (lower))) -
          1);
}
inline int onbits_count(unsigned long long int b) {
  int c = 0;
  while (b != 0) {
    c += (b & 1);
    b >>= 1;
  }
  return c;
}
inline int bits_count(unsigned long long int b) {
  int c = 0;
  while (b != 0) {
    ++c;
    b >>= 1;
  }
  return c;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const complex<T>& d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
inline double now() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (static_cast<double>(tv.tv_sec) +
          static_cast<double>(tv.tv_usec) * 1e-6);
}
inline vector<string> split(string s, char delimiter) {
  vector<string> v;
  string t;
  for (typeof(s.length()) i = (0); i < (s.length()); ++i) {
    if (s[i] == delimiter)
      v.push_back(t), t = "";
    else
      t += s[i];
  }
  v.push_back(t);
  return v;
}
inline string join(vector<string> s, string j) {
  string t;
  for (typeof(s.size()) i = (0); i < (s.size()); ++i) {
    t += s[i] + j;
  }
  return t;
}
complex<int> dydx4[4] = {complex<int>(-1, 0), complex<int>(0, 1),
                         complex<int>(1, 0), complex<int>(0, -1)};
complex<int> dydx8[8] = {complex<int>(-1, 0), complex<int>(0, 1),
                         complex<int>(1, 0),  complex<int>(0, -1),
                         complex<int>(-1, 1), complex<int>(1, 1),
                         complex<int>(1, -1), complex<int>(-1, -1)};
int g_height, g_width;
bool in_field(complex<int> p) {
  return (0 <= p.real() && p.real() < g_height) &&
         (0 <= p.imag() && p.imag() < g_width);
}
bool opt_debug = false;
class Cumulative {
  int jungle, ocean, ice;

 public:
  Cumulative();
  Cumulative(int _j, int _o, int _i);
  void add_with_char(char c) {
    switch (c) {
      case 'J':
        jungle++;
        break;
      case 'O':
        ocean++;
        break;
      case 'I':
        ice++;
        break;
    }
  }
  Cumulative& operator+=(const Cumulative& rhs) {
    this->jungle += rhs.jungle;
    this->ocean += rhs.ocean;
    this->ice += rhs.ice;
    return *this;
  }
  Cumulative& operator-=(const Cumulative& rhs) {
    this->jungle -= rhs.jungle;
    this->ocean -= rhs.ocean;
    this->ice -= rhs.ice;
    return *this;
  }
  void print() { printf("%d %d %d", jungle, ocean, ice); }
};
Cumulative::Cumulative() {}
Cumulative::Cumulative(int _j, int _o, int _i)
    : jungle(_j), ocean(_o), ice(_i) {}
int main(int argc, char** argv) {
  std::ios_base::sync_with_stdio(false);
  int __c;
  while ((__c = getopt(argc, argv, "d")) != -1) {
    switch (__c) {
      case 'd':
        opt_debug = true;
        break;
      default:
        abort();
    }
  }
  int M, N;
  cin >> M >> N;
  int K;
  cin >> K;
  vector<vector<char> > field(M, vector<char>(N));
  for (typeof(M) i = (0); i < (M); ++i) {
    for (typeof(N) j = (0); j < (N); ++j) {
      cin >> field[i][j];
    }
  }
  vector<vector<Cumulative> > cumulatives(M, vector<Cumulative>(N));
  for (typeof(M) i = (0); i < (M); ++i) {
    for (typeof(N) j = (0); j < (N); ++j) {
      Cumulative c(0, 0, 0);
      if (i > 0) {
        c += cumulatives[i - 1][j];
      }
      if (j > 0) {
        c += cumulatives[i][j - 1];
      }
      if (i > 0 && j > 0) {
        c -= cumulatives[i - 1][j - 1];
      }
      c.add_with_char(field[i][j]);
      cumulatives[i][j] = c;
    }
  }
  for (typeof(K) _ = (0); _ < (K); ++_) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b, --c, --d;
    Cumulative ans = cumulatives[c][d];
    if (a > 0) {
      ans -= cumulatives[a - 1][d];
    }
    if (b > 0) {
      ans -= cumulatives[c][b - 1];
    }
    if (a > 0 && b > 0) {
      ans += cumulatives[a - 1][b - 1];
    }
    ans.print();
    cout << endl;
  }
  return 0;
}
