#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, h, w;
  int dif;
  int a[600][600] = {};
  scanf("%d", &q);
  for (int k = 0; k < q; k++) {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", a[i] + j);
      }
    }
    dif = 0;
    for (int j = 0; j < w; j++) {
      dif += abs(a[h / 2][j] - a[h / 2 - 1][j]);
    }
    if (dif > w * 30)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
