#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[2005][2005];
int c[2005];
bitset<2005> b[2005];
int e[2005][2005];
pair<int, int> ed[2005];
int cnt;
pair<int, int> q[2005 * 2005];
bool vis[2005];
int dsu[2005];
int getdsu(int x) { return dsu[x] == x ? x : dsu[x] = getdsu(dsu[x]); }
bool doit() {
  int head = 1, tail = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j && (b[i] & b[j]) == b[i])
        e[i][j] = 1, q[++tail] = {i, j};
      else
        e[i][j] = 0;
  for (int i = 1; i <= n; ++i) dsu[i] = i;
  memset(vis, 0, sizeof(bool) * (n + 1));
  cnt = 0;
  while (head <= tail && cnt < n - 1) {
    int u = q[head].first, v = q[head].second;
    ++head;
    if (vis[u] || vis[v] || getdsu(u) == getdsu(v)) continue;
    dsu[getdsu(u)] = getdsu(v);
    ed[++cnt] = {u, v};
    vis[u] = 1;
    for (int i = 1; i <= m; ++i)
      if (b[u][i]) {
        if (--c[i] == 1) b[v][i] = 0;
      }
    for (int i = 1; i <= n; ++i)
      if (!vis[i] && i != v && !e[v][i] && (b[v] & b[i]) == b[v])
        e[v][i] = 1, q[++tail] = {v, i};
  }
  return cnt == n - 1;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) b[i].reset();
    for (int i = 1; i <= m; ++i) {
      scanf("%s", str[i] + 1);
      c[i] = 0;
      for (int j = 1; j <= n; ++j) c[i] += (str[i][j] == '1');
      if (c[i] > 1)
        for (int j = 1; j <= n; ++j)
          if (str[i][j] == '1') b[j][i] = 1;
    }
    if (!doit())
      printf("NO\n");
    else {
      printf("YES\n");
      for (int i = 1; i < n; ++i) printf("%d %d\n", ed[i].first, ed[i].second);
    }
  }
  return 0;
}
