#include <bits/stdc++.h>
using namespace std;
int evalFunc(const int x, const int y) { return abs(x - y); }
int main() {
  int photo[601][601];
  int w, h;
  int q;
  scanf("%d ", &q);
  for (int photoID = 0; photoID < q; photoID++) {
    scanf("%d %d", &h, &w);
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        scanf(" %d", &photo[x][y]);
      }
    }
    int contrast1 = 0;
    int contrast2 = 0;
    for (int i = 0; i < w; i++)
      contrast1 += evalFunc(photo[i][h / 2 - 1], photo[i][h / 2]);
    for (int i = 0; i < w; i++)
      contrast2 += evalFunc(photo[i][h - 1], photo[i][0]);
    if (contrast1 > contrast2) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
