#include <bits/stdc++.h>
using namespace std;
const double Pi = 3.1415926536;
int main() {
  int q;
  cin >> q;
  for (int g = 0; g < q; ++g) {
    int h, w;
    cin >> h >> w;
    long long a = 0, b = 0;
    int mas[500][500];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> mas[i][j];
      }
    }
    for (int i = 0; i < w; ++i) {
      a += abs(mas[h / 2][i] - mas[(h - 1) / 2][i]);
      b += abs(mas[h - 1][i] - mas[0][i]);
    }
    if (a > b)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
