#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m;
char S[N][N];
int cnt[N], Ex[N], Ey[N];
bitset<N> A[N];
queue<int> q[N];
bool vis[N];
int main() {
  int Case;
  scanf("%d", &Case);
  while (Case--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
      A[i].reset(), vis[i] = false, q[i] = queue<int>();
    for (int i = 1; i <= m; i++) {
      scanf("%s", S[i] + 1), cnt[i] = 0;
      for (int j = 1; j <= n; j++)
        if (S[i][j] == '1') cnt[i]++, A[j][i] = 1;
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (i != j && (A[i] & A[j]) == A[i]) q[i].push(j);
    bool ok = true;
    for (int T = 1; T <= n - 1; T++) {
      for (int i = 1; i <= m; i++)
        if (cnt[i] == 1) {
          for (int j = 1; j <= n; j++)
            if (S[i][j] == '1') {
              A[j][i] = 0;
              for (int k = 1; k <= n; k++)
                if (!vis[k] && k != j && (A[j] & A[k]) == A[j]) q[j].push(k);
            }
          cnt[i] = 0;
        }
      Ex[T] = 0;
      for (int i = 1; i <= n; i++)
        if (!vis[i]) {
          while (!q[i].empty() && vis[q[i].front()]) q[i].pop();
          if (q[i].empty()) continue;
          int v = q[i].front();
          Ex[T] = i, Ey[T] = v;
          vis[i] = true;
          for (int j = 1; j <= m; j++)
            if (S[j][i] == '1') S[j][i] = '0', --cnt[j];
          break;
        }
      if (!Ex[T]) {
        ok = false;
        break;
      }
    }
    if (!ok)
      puts("NO");
    else {
      puts("YES");
      for (int i = 1; i <= n - 1; i++) printf("%d %d\n", Ex[i], Ey[i]);
    }
  }
  return 0;
}
