#include <bits/stdc++.h>
using namespace std;
int tata[2010], g[2010];
vector<pair<int, int>> edges;
bitset<2001> secret[2001];
int find(int x) {
  return (tata[tata[x]] == tata[x] ? tata[x] : tata[x] = find(tata[x]));
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  assert(a != b);
  if (g[a] >= g[b])
    tata[b] = a, g[a] += g[b];
  else
    tata[a] = b, g[b] += g[a];
}
void test() {
  edges.clear();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    tata[i] = i, g[i] = 1;
    secret[i] = bitset<2001>();
  }
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) secret[j][i] = s[j] - '0';
  }
  vector<pair<int, pair<int, int>>> ord;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      ord.push_back({(secret[i] & secret[j]).count(), {i, j}});
  sort(ord.rbegin(), ord.rend());
  for (auto i : ord) {
    if (find(i.second.first) == find(i.second.second)) continue;
    unite(i.second.first, i.second.second);
    edges.push_back({i.second.first, i.second.second});
  }
  for (int i = 0; i < m; i++) {
    int nr = 0;
    for (int j = 0; j < n; j++) nr += secret[j][i];
    for (auto j : edges) nr -= secret[j.first][i] & secret[j.second][i];
    if (nr != 1) {
      cout << "NO\n";
      return;
    }
  }
  cout << "YES\n";
  for (auto i : edges) cout << i.first + 1 << ' ' << i.second + 1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) test();
  return 0;
}
