#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
bitset<N> MySet[N];
int n, m, need, fa[N], ecnt, tcnt, cur;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
struct edge {
  int from, to, w;
  edge(int f = 0, int t = 0, int c = 0) : from(f), to(t), w(c) {}
  bool operator<(const edge& ed) const { return w > ed.w; }
} e[N * N];
pair<int, int> ans[N];
char tmp[N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    memset(MySet, 0, sizeof MySet);
    cur = tcnt = need = ecnt = 0;
    for (int i = 1; i <= n; ++i) fa[i] = i;
    for (int i = 1; i <= m; ++i) {
      int cnt = 0;
      scanf("%s", tmp + 1);
      for (int j = 1; j <= n; ++j)
        if (tmp[j] == '1') cnt++, MySet[j].set(i);
      need += cnt - 1;
    }
    for (int i = 1; i <= n; ++i)
      for (int j = i + 1; j <= n; ++j)
        e[++ecnt] = edge(i, j, (MySet[i] & MySet[j]).count());
    sort(e + 1, e + 1 + ecnt);
    for (int i = 1; tcnt < n && i <= ecnt; ++i) {
      int x = find(e[i].from), y = find(e[i].to);
      if (x == y) continue;
      cur += e[i].w, fa[x] = y;
      ans[++tcnt] = {e[i].from, e[i].to};
    }
    if (cur != need) {
      puts("NO");
      continue;
    }
    puts("YES");
    for (int i = 1; i <= n - 1; ++i)
      printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
