#include <bits/stdc++.h>
using namespace std;

int t,l[305][305],u[305][305],n,m;
int main() {
  cin>>t;
  for (int i=1;i<=t;i++){
    cin>>n>>m;
    for (int j=1;j<=n;j++){
      for (int k=1;k<=m;k++){
        cin>>l[i][j];
      }
    }
    for (int j=1;j<=n;j++){
      for (int k=1;k<=m;k++){
        cin>>u[i][j];
        //if (u[i][j]==l[i][j]) br++;
      }
    }
    cout<<"NE"<<endl;
  }

  return 0;
}