#include <bits/stdc++.h>
using namespace std;
const int N = 605;
int n, m, a[N][N], cnt, DIF;
bool yes;
int check(int x, int y) {
  int ret = 0;
  for (int i = 0; i < (m); i++) {
    ret += pow(a[x][i] - a[y][i], 2);
  }
  return ret;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < (n); i++)
      for (int j = 0; j < (m); j++) scanf("%d", &a[i][j]);
    bool f = 1;
    yes = 0;
    DIF = m * 300;
    for (int i = 0; i < (n); i++) {
      if (i == 0 || i == n - 1) continue;
      int cnt = 0;
      if (check(i, i - 1) > DIF && check(i, i + 1) > DIF) {
        f = 1;
        break;
      }
    }
    if (f && check(0, n - 1) < DIF) yes = 1;
    if (yes)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
