#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 7;
constexpr long long INFL = 1e18;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
constexpr int maxn = 2005;
int n, m;
bitset<maxn> B[maxn];
bool comm[maxn][maxn];
int rem[maxn][maxn], cnt[maxn];
bool used[maxn];
vector<int> G[maxn];
bool vis[maxn];
void dfs(int a, int ind) {
  vis[a] = true;
  for (auto v : G[a]) {
    if (vis[v] or not comm[ind][v]) continue;
    dfs(v, ind);
  }
}
bool check() {
  for (int i = 0; i < m; i++) {
    fill(vis, vis + n, false);
    auto s = find(comm[i], comm[i] + n, true) - comm[i];
    dfs(s, i);
    for (int j = 0; j < n; j++)
      if (comm[i][j] and not vis[j]) return false;
  }
  return true;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      B[i].reset();
      G[i].clear();
    }
    fill(cnt, cnt + m, 0);
    fill(used, used + n, false);
    for (int i = 0; i < m; i++) {
      char c = getchar();
      if (c < 33) c = getchar();
      for (int j = 0; j < n; j++) {
        cnt[i] += (B[j][i] = (c == '1'));
        comm[i][j] = (c == '1');
        c = getchar();
      }
    }
    queue<pair<int, int>> Q;
    auto erase = [&](int mi) {
      cnt[mi] = 0;
      int v = 0;
      for (int &i = v; i < n; i++)
        if (not used[i] and B[i][mi]) break;
      assert(v < n);
      for (int i = 0; i < n; i++) {
        if (used[i] or i == v) continue;
        if (--rem[v][i] == 0) Q.emplace(v, i);
      }
    };
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        rem[i][j] = ((B[i] ^ B[j]) & B[i]).count();
        if (rem[i][j] == 0) Q.emplace(i, j);
      }
    for (int i = 0; i < m; i++)
      if (cnt[i] == 1) erase(i);
    vector<pair<int, int>> ans;
    while (not Q.empty()) {
      int a, b;
      tie(a, b) = Q.front();
      Q.pop();
      if (used[a] or used[b]) continue;
      ans.emplace_back(a, b);
      G[a].emplace_back(b);
      G[b].emplace_back(a);
      used[a] = true;
      for (int i = 0; i < m; i++)
        if ((cnt[i] -= B[a][i]) == 1) erase(i);
    }
    if (ans.size() < n - 1 or not check())
      puts("NO");
    else {
      puts("YES");
      for (auto e : ans) printf("%d %d\n", e.first + 1, e.second + 1);
    }
  }
}
