#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 2005;
int n, m;
bitset<2005> a[MAXN];
int w[MAXN][MAXN];
int parent[MAXN];
vector<int> who[MAXN];
vector<int> g[MAXN];
int findset(int v) {
  if (v == parent[v]) {
    return v;
  }
  return parent[v] = findset(parent[v]);
}
int col[MAXN];
int uk = 0;
int dfs(int u, int pr = -1) {
  int cnt = 1;
  for (auto h : g[u]) {
    if (h == pr || col[h] != uk) {
      continue;
    }
    cnt += dfs(h, u);
  }
  return cnt;
}
bool check(vector<int> x) {
  uk++;
  for (auto y : x) {
    col[y] = uk;
  }
  return dfs(x[0]) == (int)(x).size();
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    a[i].reset();
    parent[i] = i;
    g[i].clear();
  }
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    who[i].clear();
    for (int j = 0; j < n; j++) {
      if (s[j] == '1') {
        who[i].push_back(j);
        a[j][i] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      w[i][j] = (a[i] & a[j]).count();
    }
  }
  vector<pair<int, pair<int, int> > > st;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      st.push_back({w[i][j], make_pair(i, j)});
    }
  }
  sort((st).begin(), (st).end());
  reverse((st).begin(), (st).end());
  vector<pair<int, int> > sts;
  for (auto x : st) {
    int ta = x.second.first;
    int tb = x.second.second;
    if (findset(ta) != findset(tb)) {
      parent[findset(ta)] = findset(tb);
      sts.push_back(make_pair(ta, tb));
      g[ta].push_back(tb);
      g[tb].push_back(ta);
    }
  }
  bool bad = false;
  for (int i = 0; i < m; i++) {
    if (!check(who[i])) {
      bad = true;
      break;
    }
  }
  if (bad) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  for (auto x : sts) {
    cout << x.first + 1 << ' ' << x.second + 1 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
