#include <bits/stdc++.h>
using namespace std;
int mat[605][605];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int w, h;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) cin >> mat[i][j];
    long long dist = 0;
    for (int i = 0; i < w; i++) dist += abs(mat[h / 2][i] - mat[h / 2 - 1][i]);
    cout << (dist / w <= 26 ? "NO" : "YES") << endl;
  }
}
