#include <bits/stdc++.h>
namespace FastIO {
template <typename T>
inline void readInteger(T& ret) {
  char ch = getchar();
  bool flag = false;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    flag = true;
    ch = getchar();
  }
  ret = 0;
  while (ch >= '0' && ch <= '9') {
    ret = ret * 10 + (ch - '0');
    ch = getchar();
  }
  if (flag) ret = -ret;
}
inline int nextInt() {
  int x;
  readInteger(x);
  return x;
}
inline long long nextLong() {
  long long x;
  readInteger(x);
  return x;
}
template <typename T>
inline void outInteger(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) {
    outInteger(x / 10);
  }
  putchar(x % 10 + '0');
}
inline void newline() { putchar('\n'); }
}  // namespace FastIO
using namespace std;
using namespace FastIO;
int H, W;
int board[1100][1100];
int main() {
  int T;
  int s1, s2;
  for (scanf("%d", &T); T--;) {
    scanf("%d%d", &H, &W);
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++) scanf("%d", &board[i][j]);
    s1 = s2 = 0;
    for (int j = 0; j < W; j++) {
      s1 += abs(board[H / 2 - 1][j] - board[H / 2][j]);
      s2 += abs(board[0][j] - board[H - 1][j]);
    }
    if (s1 > s2)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
