#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2050;
int n, m, cnt[MAXN], id[MAXN][MAXN];
vector<int> v[MAXN];
bitset<MAXN> a[MAXN];
bool dead[MAXN];
vector<pair<int, int> > ans;
inline void printV() {
  for (int i = 1; i <= n; i++) {
    printf("[%d]: ", i);
    for (auto e : v[i]) printf("%d ", e);
    printf("\n");
  }
}
void update(int s, int t) {
  dead[s] = true;
  v[s].clear();
  for (int i = 1; i <= n; i++)
    if (!dead[i] && id[s][i] != -1) {
      if ((int)v[i].size() == 1) {
        v[i].clear();
      } else {
        if (v[i].back() == s)
          v[i].pop_back();
        else {
          int l = v[i].back();
          id[l][i] = id[s][i];
          v[i][id[l][i]] = l;
          v[i].pop_back();
        }
      }
    }
  for (int i = 1; i <= n; i++) id[s][i] = id[i][s] = -1;
  for (int x = 0; x < m; x++)
    if (a[s][x] == 1) cnt[x]--;
  a[s] = 0;
  for (int x = 0; x < m; x++)
    if (cnt[x] == 1 && a[t][x] == 1) {
      a[t][x] = 0;
      cnt[x] = 0;
    }
  for (int i = 1; i <= n; i++) {
    if (t == i || dead[i] || id[i][t] != -1) continue;
    if ((a[i] & a[t]) == a[t]) {
      id[i][t] = (int)v[t].size();
      v[t].push_back(i);
    }
  }
}
char s[MAXN];
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    a[i] = 0;
    v[i].clear();
    dead[i] = false;
    for (int j = 1; j <= n; j++) id[i][j] = -1;
  }
  for (int x = 0; x < m; x++) cnt[x] = 0;
  ans.clear();
  for (int x = 0; x < m; x++) {
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
      a[i][x] = (s[i] - '0');
      if (s[i] == '1') cnt[x]++;
    }
    if (cnt[x] <= 1)
      for (int i = 1; i <= n; i++) a[i][x] = 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if ((a[i] & a[j]) == a[i]) {
        id[j][i] = (int)v[i].size();
        v[i].push_back(j);
      }
    }
  for (int step = 0; step < n - 1; step++) {
    int s = -1;
    for (int i = 1; i <= n; i++)
      if (!dead[i] && !v[i].empty()) {
        s = i;
        break;
      }
    if (s == -1) {
      printf("NO\n");
      return;
    }
    int t = v[s].back();
    ans.emplace_back(s, t);
    update(s, t);
  }
  printf("YES\n");
  for (auto e : ans) printf("%d %d\n", e.first, e.second);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
