#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int n,m,q;
  cin>>n>>m>>q;
  vector<string> s(n);
  for(Int i=0;i<n;i++) cin>>s[i];

  auto J=make_v<Int>(n+1,m+1);
  auto O=make_v<Int>(n+1,m+1);
  auto I=make_v<Int>(n+1,m+1);

  fill_v(J,0);
  fill_v(O,0);
  fill_v(I,0);

  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++){
      J[i+1][j+1]=J[i+1][j]+(s[i][j]=='J');
      O[i+1][j+1]=O[i+1][j]+(s[i][j]=='O');
      I[i+1][j+1]=I[i+1][j]+(s[i][j]=='I');
    }
  }

  for(Int i=0;i<n;i++){
    for(Int j=0;j<=m;j++){
      J[i+1][j]+=J[i][j];
      O[i+1][j]+=O[i][j];
      I[i+1][j]+=I[i][j];
    }
  }

  auto calc=[](auto &dp,Int a,Int b,Int c,Int d){
    return (dp[c][d]+dp[a][b])-(dp[c][b]+dp[a][d]);
  };
  
  for(Int i=0;i<q;i++){
    Int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;b--;
    cout<<calc(J,a,b,c,d)<<" "<<calc(O,a,b,c,d)<<" "<<calc(I,a,b,c,d)<<endl;
  }
  
  
  return 0;
}

