#include <bits/stdc++.h>
using namespace std;
int q, h, w;
int a[605][605];
int main() {
  ios_base::sync_with_stdio(0);
  ifstream in("sample.in");
  cin >> q;
  for (int k = 0; k < q; k++) {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> a[i][j];
      }
    }
    int up = max(0, h / 2 - 1);
    int down = min(h - 1, h / 2);
    double sum1 = 0;
    for (int j = 0; j < w; j++) {
      sum1 += 1.0 * abs(a[up][j] - a[down][j]) / 255;
    }
    sum1 /= w;
    double sum2 = 0;
    for (int j = 0; j < w; j++) {
      sum2 += 1.0 * abs(a[0][j] - a[h / 2][j]) / 255;
    }
    sum2 /= w;
    cout << (sum1 < sum2 ? "NO\n" : "YES\n");
  }
}
