#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
// 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> >;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#undef NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		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(ALL(res));
    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){// [0,n)
			T s=0;
			while(n>0){
				s+=bit[n];
				n-=n&-n;//low
			}
			return s;
		}
		void add(int i,T x){//[0,...i...,n-1)
			i++;
			while(i<=size){
				bit[i]+=x;
				i+=i & -i;//next
			}
		}
		
		//lib
		T sum(int a,int b){// [a,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){// [0, y) x [0, x) 
			T s=0;
			while(y>0){
				s += fs[y].sum(x);
				y-=y&-y;//low
			}
			return s;
		} 
		void add(int y,int x,T v){//(x,y)
			y++;
			while(y<=H){
				fs[y].add(x,v);
				y+=y & -y;//next
			}
		}

		//lib
		T sum(int y1,int x1,int y2,int x2){//[x1,x2)×[y1,y2)
			return sum(y2,x2)-sum(y2,x1)-sum(y1,x2)+sum(y1,x1);
		}
	};
}
using namespace Fenwicks;

class Main{
public:
	void run(){
		int H,W;cin >> H >> W;
		int Q;cin >> Q;
		vector<string> board(H);
		REP(y,H)cin >> board[y];

		Fenwick2D<int> J(H,W),O(H,W),I(H,W);
		REP(y,H)REP(x,W){
			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);
		}

		REP(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;
 }

Measured memory_bytes: 13940