#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
const int oo = 1e9, bpr = 1e9 + 7, N = 610;
int a[N][N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int q, n, m;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        scanf("%d", &a[i][j]);
      }
    }
    int res1 = 0, res2 = 0;
    for (int j = 1; j <= m; ++j) {
      res1 += abs(a[n / 2 + 1][j] - a[n / 2][j]);
      res2 += abs(a[n][j] - a[1][j]);
    }
    if (res2 < res1)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
