#include <bits/stdc++.h>
using namespace std;
const int MaxN = 610;
int w[MaxN][MaxN];
inline int sqr(int x) { return x * x; }
bool solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &w[i][j]);
  int sum = 0;
  for (int i = 1; i <= m; ++i) sum += sqr(w[n / 2][i] - w[n / 2 + 1][i]);
  return sum > 500000;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--)
    if (solve())
      puts("YES");
    else
      puts("NO");
  return 0;
}
