#include <bits/stdc++.h>
using namespace std;
const int MN = 1011;
const int inf = 1e9 + 7;
int n, a[MN][MN];
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  while (n--) {
    int h, w;
    cin >> h >> w;
    for (int i = (1), _b = (h); i <= _b; ++i)
      for (int j = (1), _b = (w); j <= _b; ++j) cin >> a[i][j];
    long long sum = 0;
    for (int i = (1), _b = (w); i <= _b; ++i)
      sum += abs(a[h / 2][i] - a[h / 2 + 1][i]);
    sum /= w;
    if (sum > 21)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
