#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int diff = 20;
int h, w, g[650][650], q;
bool chk() {
  int r = h / 2, cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < w; i++) {
    if (abs(g[r - 1][i] - g[r][i]) < diff) {
      ++cnt1;
    }
  }
  for (int i = 0; i < w; i++) {
    if (abs(g[0][i] - g[h - 1][i]) < diff) {
      ++cnt2;
    }
  }
  return cnt2 > cnt1;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &g[i][j]);
      }
    }
    puts(chk() ? "YES" : "NO");
  }
  return 0;
}
