#include <bits/stdc++.h>
const int MAXH = 606;
const int MAXW = 606;
int pic[MAXH][MAXW];
int ques, h, w;
inline int find_diff(int rowa, int rowb) {
  int res = 0;
  for (int col = 1; col <= w; col++)
    res += abs(pic[rowa][col] - pic[rowb][col]);
  return res;
}
inline void input(void) {
  scanf("%d%d", &h, &w);
  for (int row = 1; row <= h; row++)
    for (int col = 1; col <= w; col++) scanf("%d", &pic[row][col]);
}
inline void solve() {
  int diff_top = find_diff(1, h);
  int diff_half = find_diff(h / 2, h / 2 + 1);
  if (diff_top > diff_half)
    puts("NO");
  else
    puts("YES");
}
int main() {
  scanf("%d", &ques);
  for (int cascnt = 1; cascnt <= ques; cascnt++) {
    input();
    solve();
  }
  return 0;
}
