#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 2000;
const int MAXGROUP = 2000;
int n, ngroup;
char group[MAXGROUP][MAXN + 1];
vector<pair<int, int>> ans;
int groupremcnt[MAXGROUP];
int extra[MAXN][MAXN];
bitset<MAXGROUP> bs[MAXN];
int cnt[MAXN];
queue<pair<int, int>> q;
bool done[MAXN];
int ufpar[MAXN], ufsz[MAXN];
int uffind(int a) {
  if (ufpar[a] == a) return a;
  return ufpar[a] = uffind(ufpar[a]);
}
void ufunite(int a, int b) {
  a = uffind(a), b = uffind(b);
  if (a == b) return;
  if (ufsz[a] < ufsz[b]) swap(a, b);
  ufpar[b] = a, ufsz[a] += ufsz[b];
}
bool solve() {
  for (int i = (0); i < (ngroup); ++i) {
    groupremcnt[i] = 0;
    for (int j = (0); j < (n); ++j)
      if (group[i][j] == '1') ++groupremcnt[i];
  }
  for (int i = (0); i < (ngroup); ++i)
    if (groupremcnt[i] >= 2)
      for (int j = (0); j < (n); ++j)
        if (group[i][j] == '1') bs[j][i] = 1;
  for (int i = (0); i < (n); ++i) cnt[i] = bs[i].count();
  for (int i = (0); i < (n); ++i)
    for (int j = (i + 1); j < (n); ++j) {
      int common = (bs[i] & bs[j]).count();
      extra[i][j] = cnt[i] - common;
      extra[j][i] = cnt[j] - common;
    }
  ans.clear();
  q = queue<pair<int, int>>();
  for (int i = (0); i < (n); ++i) done[i] = false, ufpar[i] = i, ufsz[i] = 1;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j)
      if (i != j && extra[i][j] == 0) q.push(make_pair(i, j));
  while (!q.empty()) {
    int leaf = q.front().first, parent = q.front().second;
    q.pop();
    if (done[leaf] || done[parent] || uffind(leaf) == uffind(parent)) continue;
    done[leaf] = true;
    ans.push_back(make_pair(leaf, parent));
    ufunite(leaf, parent);
    for (int i = (0); i < (ngroup); ++i)
      if (groupremcnt[i] >= 2 && group[i][leaf] == '1') {
        --groupremcnt[i];
        if (groupremcnt[i] == 1) {
          for (int to = (0); to < (n); ++to)
            if (!done[to]) {
              --extra[parent][to];
              if (extra[parent][to] == 0) q.push(make_pair(parent, to));
            }
        }
      }
  }
  for (int i = (0); i < (ngroup); ++i)
    for (int j = (0); j < (n); ++j) bs[j][i] = 0;
  return ((int)(ans).size()) == n - 1;
}
void run() {
  scanf("%d%d", &n, &ngroup);
  for (int i = (0); i < (ngroup); ++i) scanf("%s", group[i]);
  if (!solve()) {
    printf("NO\n");
    return;
  }
  printf("YES\n");
  for (int i = (0); i < (((int)(ans).size())); ++i)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
int main() {
  for (int i = (0); i < (MAXN); ++i) bs[i] = 0;
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) run();
  return 0;
}
