/*
 * Created by SharpDevelop.
 * User: Watson
 * Date: 2017/04/28
 * Time: 21:17
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Collections;

namespace NU
{
	class Program
	{
		static Func<int> Read=()=>int.Parse(Console.ReadLine());
		static Func<string[]> Readss=()=>Console.ReadLine().Split(' ');
		static string[] ss=new string[4];
		static Func<int,int> par = i=>int.Parse(ss[i]);
			static int[,]juns,ices,oces;
		public static void Main(string[] args)
		{
			string s;
			ss=Readss();
			int M=par(0),N=par(1);
			juns=new int[N+1,M+1];ices=new int[N+1,M+1];oces=new int[N+1,M+1];
			int K=Read();
			int j;
			for(j=0;j<N;j++){juns[j,0]=0;oces[j,0]=0;ices[j,0]=0;
				}
			for(int i=0;i<M;i++){
				s=Console.ReadLine();
				j=0;
				juns[0,i+1]=0;
				foreach(char c in s){
					juns[j+1,i+1]=0;
					oces[j+1,i+1]=0;
					ices[j+1,i+1]=0;
					switch(c){
							case 'J':juns[j+1,i+1]=1;break;
							case 'O':oces[j+1,i+1]=1;break;
							case 'I':ices[j+1,i+1]=1;break;
					}
					j++;
					if(j>=N)break;
				}	//kakugyounosouwa
			}
			
			for(int i=1;i<M+1;i++){
				for(j=0;j<N+1;j++){
					oces[j,i]+=oces[j,i-1];
					ices[j,i]+=ices[j,i-1];
					juns[j,i]+=juns[j,i-1];
				}
			}
			for(int i=0;i<M+1;i++){
				for(j=1;j<N+1;j++){
					oces[j,i]+=oces[j-1,i];
					ices[j,i]+=ices[j-1,i];
					juns[j,i]+=juns[j-1,i];
				}
			}
			string Res;
			int a,aa,aaa,aaaa;
			for(int h=0;h<K;h++){
				ss=Readss();
				a=par(0);aa=par(1);aaa=par(2);aaaa=par(3);
				Res=Cons(juns,aa,a,aaaa,aaa)+" "+
				                Cons(oces,aa,a,aaaa,aaa)+" "+
				                Cons(ices,aa,a,aaaa,aaa);
				Console.WriteLine(Res);
			}
		}
		
		public static int Cons(int[,] K,int sx,int sy,int ex,int ey){
			return K[ex+1,ey+1]-K[ex+1,sy+1]-K[sx+1,ey+1]+K[sx+1,sy+1];
		}
	}
	
}