#include <bits/stdc++.h>
using namespace std;
int a[603][603];
const int R_VAL = 20;
const int M_VAL = 33;
int main() {
  int q, w, h, i, j, ansv, mansv;
  cin >> q;
  while (q--) {
    scanf("%d%d", &h, &w);
    for (i = 0; i < h; ++i) {
      for (j = 0; j < w; ++j) {
        scanf("%d", &a[i][j]);
      }
    }
    ansv = 0;
    mansv = 0;
    for (i = 0; i < w; ++i) {
      ansv += abs(a[0][i] - a[h / 2 - 1][i]);
      mansv += abs(a[h / 2 - 1][i] - a[h / 2][i]);
    }
    ansv /= w;
    mansv /= w;
    if ((mansv > R_VAL)) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
}
