#include <bits/stdc++.h>
using namespace std;
int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 2005;
const int L = 4e6 + 5;
int n, m;
bitset<N> b[N];
char s[N];
pair<int, pair<int, int> > e[L];
int fa[N];
int ed[N][2];
int getfather(int x) { return fa[x] == x ? x : fa[x] = getfather(fa[x]); }
void solve() {
  n = get();
  m = get();
  for (int i = 1; i <= n; i++) b[i].reset();
  for (int i = 1; i <= m; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++)
      if (s[j] == '1')
        b[j][i] = 1;
      else
        b[j][i] = 0;
  }
  int k = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      e[++k] = make_pair(-(b[i] & b[j]).count(), make_pair(i, j));
  sort(e + 1, e + 1 + k);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int u = 0;
  for (int i = 1; i <= k; i++) {
    int x = e[i].second.first, y = e[i].second.second;
    int tx = getfather(x), ty = getfather(y);
    if (tx == ty) continue;
    ed[++u][0] = x;
    ed[u][1] = y;
    fa[tx] = ty;
  }
  bool yes = 1;
  for (int i = 1; i <= m; i++) {
    int siz = 0;
    for (int x = 1; x <= n; x++)
      if (b[x][i]) siz++;
    for (int x = 1; x <= u; x++)
      if (b[ed[x][1]][i] && b[ed[x][0]][i]) siz--;
    if (siz != 1) {
      yes = 0;
      break;
    }
  }
  if (yes) {
    printf("YES\n");
    for (int i = 1; i <= n - 1; i++) printf("%d %d\n", ed[i][0], ed[i][1]);
  } else
    printf("NO\n");
}
int main() {
  for (int T = get(); T; T--) solve();
  return 0;
}
