#include <bits/stdc++.h>
using namespace std;
int h, w;
int str[700][700];
const int x = 5;
void Compute() {
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 1; i <= w; i++) {
    if (abs(str[h / 2][i] - str[h / 2 + 1][i]) > x) cnt1++;
  }
  for (int i = 1; i <= w; i++) {
    if (abs(str[1][i] - str[h][i]) > x) cnt2++;
  }
  if (cnt1 > cnt2)
    printf("YES\n");
  else
    printf("NO\n");
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &h, &w);
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        scanf("%d", &str[i][j]);
      }
    }
    Compute();
  }
  return 0;
}
