#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int sqr(int x) { return x * x; }
int n, m, q;
int a[1001][1001];
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &n, &m);
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++) scanf("%d", &a[j][k]);
    int ans = 0, ans2 = 0;
    for (int j = 1; j <= m; j++) ans += sqr(a[n / 2][j] - a[n / 2 + 1][j]);
    for (int j = 1; j <= m; j++) ans2 += sqr(a[1][j] - a[n][j]);
    if (ans < ans2)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
