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