#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void gn(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
template <typename T>
inline void gt(T x) {
  if (!x) return;
  gt(x / 10);
  putchar(x % 10 + '0');
}
int t, n, m, a[666][666];
long long MOD = 1e9 + 7;
void solve() {
  int i, j, k, l, x = 0, y = 0;
  gn(n);
  gn(m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) gn(a[i][j]);
  for (i = 1; i <= m; i++) {
    x += abs(a[(n / 2)][i] - a[n / 2 + 1][i]);
    y += abs(a[n][i] - a[1][i]);
  }
  puts(x > y ? "YES" : "NO");
}
int main() {
  gn(t);
  while (t--) {
    solve();
  }
  return 0;
}
