#include <bits/stdc++.h>
using namespace std;
const int MN = 2010;
int N, M;
bitset<MN> S[MN], A[MN];
vector<int> V[MN];
vector<pair<int, int> > sol;
int chk[MN], used[MN], cnt[MN], C[MN][MN], inv[MN][MN];
void main2() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    S[i].reset();
    chk[i] = 0;
    cnt[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    A[i].reset();
    V[i].clear();
    used[i] = 0;
    for (int j = 0; j < N; j++) {
      C[i][j] = 0;
      inv[i][j] = -1;
    }
  }
  sol.clear();
  for (int i = 0; i < M; i++) {
    getchar();
    for (int j = 0; j < N; j++) {
      char c = getchar();
      S[i][j] = c - '0';
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++)
      if (S[i][j]) cnt[i]++;
    if (cnt[i] == 1) chk[i] = 1;
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) A[i][j] = !chk[j] && S[j][i];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (i != j && (A[i] | A[j]) == A[j]) {
        V[i].push_back(j);
        C[i][j] = 1;
        inv[i][j] = (int)V[i].size() - 1;
      }
  for (int i = 0; i < N - 1; i++) {
    int p = -1;
    for (int j = 0; j < N; j++)
      if (!used[j] && V[j].size()) {
        p = j;
        break;
      }
    if (p == -1) {
      printf("NO\n");
      return;
    }
    int q = V[p].back();
    sol.push_back(pair<int, int>(p, q));
    used[p] = 1;
    for (int j = 0; j < N; j++)
      if (C[j][p]) {
        int x = inv[j][p];
        V[j][x] = V[j].back();
        inv[j][V[j][x]] = x;
        V[j].pop_back();
        inv[j][p] = -1;
      }
    for (int j = 0; j < M; j++)
      if (!chk[j] && S[j][p]) {
        S[j][p] = 0;
        cnt[j]--;
        if (cnt[j] == 1) {
          chk[j] = 1;
          A[q][j] = 0;
        }
      }
    for (int j = 0; j < N; j++)
      if (j != q && !used[j] && !C[q][j] && (A[q] | A[j]) == A[j]) {
        V[q].push_back(j);
        C[q][j] = 1;
        inv[q][j] = (int)V[q].size() - 1;
      }
  }
  printf("YES\n");
  for (int i = 0; i < N - 1; i++) {
    printf("%d %d\n", sol[i].first + 1, sol[i].second + 1);
  }
}
int TC;
int main() {
  scanf("%d", &TC);
  while (TC--) main2();
}
