t[1001][1001][4];m,n,i,j,x,k;f(z){return t[i][j][z]-t[m-1][j][z]-t[i][n-1][z]+t[m-1][n-1][z];}main(c){for(scanf("%d%d%d ",&m,&n,&k);x=i++<m;)for(;c=getchar()-10;++t[i][x++][c%4])for(j=4;j--;)t[i][x][j]=t[i][x-1][j];for(;i=x++<n;)for(;i++<m;)for(j=4;j--;)t[i][x][j]+=t[i-1][x][j];for(;k--;printf("%d %d %d\n",f(0),f(1),f(3)))scanf("%d%d%d%d",&m,&n,&i,&j);}