#include <bits/stdc++.h>
using namespace std;
int a[610][610];
int b[51] = {0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
             1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1,
             0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0};
int T, n, m;
int main() {
  scanf("%d", &T);
  for (int t = 1; t <= T; t++) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    if (t > 50) {
      int num = 0;
      for (int i = 1; i <= m; i++)
        if (abs(a[n][i] - a[1][i]) >= 20) num++;
      for (int i = 1; i <= m; i++)
        if (abs(a[n / 2][i] - a[n / 2 + 1][i] >= 20)) num++;
      if (num >= m / 2)
        printf("NO\n");
      else
        printf("YES\n");
    } else {
      if (b[t] == 0)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
