#include <bits/stdc++.h>
using namespace std;
int pic[601][601];
int main() {
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) scanf("%d", &pic[i][j]);
    }
    int mid = n / 2, diff = 0;
    for (int i = 0; i < m; i++) {
      if (abs(pic[0][i] - pic[n - 1][i]) < abs(pic[mid][i] - pic[mid - 1][i]))
        diff++;
      else
        diff--;
    }
    if (diff > 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
