#include <bits/stdc++.h>
using namespace std;
int A[1 << 10][1 << 10];
long long diff(int w, int A[], int B[]) {
  long long res = 0;
  int i;
  for (i = (0); i < (w); ++i) res += abs(A[i] - B[i]);
  return res;
}
int main() {
  int T, t;
  scanf("%d", &T);
  for (t = (0); t < (T); ++t) {
    int h, w;
    scanf("%d%d", &h, &w);
    int i, j;
    for (i = (0); i < (h); ++i)
      for (j = (0); j < (w); ++j) scanf("%d", &A[i][j]);
    vector<pair<long long, int>> v;
    v.push_back(make_pair(0, 0));
    for (i = (1); i < (h); ++i)
      v.push_back(make_pair(diff(w, A[i - 1], A[i]), i));
    pair<long long, int> t = v[h / 2];
    sort((v).begin(), (v).end());
    int pos = lower_bound((v).begin(), (v).end(), t) - v.begin() + 1;
    int all = int((v).size());
    bool res = (pos + 0.0) / all < 0.9;
    printf("%s\n", res ? "NO" : "YES");
  }
  return 0;
};
