#include#include int a[105][105],dp[305][305];int main(){ int T,n,m,i,j,t,p; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); dp[0][0] = 1; scanf("%d%d",&n,&m); for(i = 0;i < n;i ++) { for(j = 0;j < m;j ++) { scanf("%d",&a[i][j]); for(t = 0;t <= a[i][j];t ++) { for(p = 0;p <= a[i][j]-t;p ++) { if(t!=0||p!=0) dp[i+t][j+p] = (dp[i+t][j+p]+dp[i][j])%10000; } } } } printf("%d\n",dp[n-1][m-1]); } return 0;}