#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, from, val;
} e[2005 * 2005];
struct Node {
  int to, nxt;
} E[2005 * 2];
int n, m, zz, ansa[2005], ansb[2005], zans, tot, head[2005], f[2005];
void build(int a, int b) {
  E[++tot].to = b;
  E[tot].nxt = head[a];
  head[a] = tot;
}
bitset<2005> A[2005], B[2005];
bool cmp(node a, node b) { return a.val > b.val; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void dfs(int p, int bl) {
  B[bl][p] = 0;
  for (int i = head[p]; i; i = E[i].nxt) {
    if (B[bl][E[i].to]) {
      dfs(E[i].to, bl);
    }
  }
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    tot = zz = zans = 0;
    memset(head, 0, sizeof head);
    scanf("%d%d", &n, &m);
    for (int a, i = 1; i <= m; ++i) {
      for (int j = 1; j <= n; ++j) {
        scanf("%1d", &a);
        B[i][j] = A[j][i] = a;
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j < i; ++j) {
        e[++zz].val = (A[i] & A[j]).count();
        e[zz].from = i;
        e[zz].to = j;
      }
    }
    for (int i = 1; i <= n; ++i) f[i] = i;
    sort(e + 1, e + 1 + zz, cmp);
    for (int a, b, i = 1; i <= zz; ++i) {
      a = find(e[i].from), b = find(e[i].to);
      if (f[a] != b) {
        ansa[++zans] = e[i].from;
        ansb[zans] = e[i].to;
        build(e[i].to, e[i].from);
        build(e[i].from, e[i].to);
        f[a] = b;
      }
    }
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (B[i][j]) {
          dfs(j, i);
          for (; j <= n; ++j) {
            if (!B[i][j]) continue;
            puts("NO");
            goto ending;
          }
        }
      }
    }
    puts("YES");
    for (int i = 1; i < n; ++i) printf("%d %d\n", ansa[i], ansb[i]);
  ending:;
    for (int i = 1; i <= max(n, m); ++i) A[i] &= 0, B[i] &= 0;
  }
  return 0;
}
