#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int h, w;
    cin >> h >> w;
    int** picture = new int*[h];
    for (int j = 0; j < h; ++j) {
      picture[j] = new int[w];
      for (int l = 0; l < w; ++l) {
        cin >> picture[j][l];
      }
    }
    int diffMid = 0, diffUp = 0;
    for (int j = 0; j < w; ++j) {
      diffMid += abs(picture[h / 2 - 1][j] - picture[h / 2][j]);
      diffUp += abs(picture[h - 1][j] - picture[0][j]);
    }
    if (diffUp <= diffMid) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
