#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 505;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int q, n, m, a[Sz][Sz];
int main() {
  Read_rap();
  cin >> q;
  while (q--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) cin >> a[i][j];
    int avg = 0;
    for (int i = 1; i <= m; i++) avg += abs(a[n / 2][i] - a[n / 2 + 1][i]);
    avg /= m;
    puts((avg >= 51 ? "YES" : "NO"));
  }
  return 0;
}
