#include <bits/stdc++.h>
using namespace std;
int q, h, w, a;
int pic[606][606];
int mabs(int x) { return (x < 0) ? -x : x; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        cin >> pic[i][j];
      }
    }
    int similar = 0;
    for (int i = 1; i <= w; i++) {
      similar += mabs(pic[1][i] - pic[h][i]);
    }
    if (similar < 30 * w) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
