#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int sgn(double d) { return d > eps ? 1 : (d < -eps ? -1 : 0); }
double trim(double d, double l = 1.0) { return d > l ? l : (d < -l ? -l : d); }
int vdiff(const vector<int>& x, const vector<int>& y) {
  int ans = 0;
  for (int i = 0; i < (x.size()); ++i) {
    ans += (x[i] - y[i]) * (x[i] - y[i]);
  }
  return ans;
}
int main() {
  int q;
  int h, w;
  scanf("%d", &q);
  for (int i = 0; i < (q); ++i) {
    scanf("%d%d", &h, &w);
    vector<vector<int> > pic;
    for (int i1 = 0; i1 < (h); ++i1) {
      vector<int> line;
      int v;
      for (int j1 = 0; j1 < (w); ++j1) {
        scanf("%d", &v);
        line.push_back(v);
      }
      pic.push_back(line);
    }
    int v1 = vdiff(pic[h / 2 - 1], pic[h / 2]);
    int v2 = vdiff(pic[0], pic[h - 1]);
    cout << (v1 < v2 ? "NO" : "YES") << endl;
  }
  return 0;
}
