#include <bits/stdc++.h>
using namespace std;
const long double EPS = 0.000001;
const int MAXN = 605;
int t[MAXN][MAXN];
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) scanf("%d", &t[i][j]);
    long long int score_ok = 0LL, score_not_ok = 0LL;
    for (int i = 0; i < w; i++) {
      int diff_ok = abs(t[h / 2 - 1][i] - t[h / 2][i]);
      int diff_not_ok = abs(t[0][i] - t[h - 1][i]);
      score_ok += (long long int)diff_ok * diff_ok;
      score_not_ok += (long long int)diff_not_ok * diff_not_ok;
    }
    if (score_ok >= score_not_ok)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
