#include <bits/stdc++.h>
using namespace std;
int arr[605][605];
int main() {
  int q, n, m;
  cin >> q;
  while (q--) {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", &arr[i][j]);
    int x = 0, y = 0;
    for (int j = 0; j < m; j++) {
      x += (arr[n / 2 - 1][j] - arr[n / 2][j]) *
           (arr[n / 2 - 1][j] - arr[n / 2][j]);
      y += (arr[0][j] - arr[n - 1][j]) * (arr[0][j] - arr[n - 1][j]);
    }
    if (y < x)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
