#include<stdio h=""> #include<string h=""> #define M 1005 int dp[M][M]; int main() { int i,j,T,temp,max,x,y,m,n; scanf("%d",&T); while(T--) { max=0; memset(dp,0,sizeof(dp)); scanf("%d%d%d%d",&m,&n,&x,&y); for(i=1;i<=m;i++) for(j=1;j<=n;j++) { scanf("%d",&dp[i][j]); dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; if(i>=x&&j>=y) { temp=dp[i][j]-dp[i-x][j]-dp[i][j-y]+dp[i-x][j-y]; if(temp>max) max=temp; } } printf("%d\n",max); } return 0; } </string></stdio>