#include #include using namespace std; int a[1005][1005]; int main() { int T; scanf("%d",&T); while(T--) { int i,j; memset(a,0,sizeof(a)); int p=0; int n,m; scanf("%d%d",&n,&m); for(i=0;i