#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int T, n, m;
char a[N];
bitset<N> S[N];
int c[N];
set<int> p[N];
void Main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%s", a);
    for (int j = 0; j < n; j++)
      if (a[j] == '1') ++c[i], S[j][i] = 1;
  }
  for (int i = 0; i < m; i++)
    if (c[i] == 1) {
      for (int j = 0; j < n; j++) S[j][i] = 0;
      c[i] = 0;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j && (S[i] & S[j]) == S[i]) p[i].insert(j);
  vector<bool> ex(n);
  vector<int> eu, ev;
  for (int i = 0; i + 1 < n; i++) {
    int x = -1, mn = 1e9;
    for (int j = 0; j < n; j++)
      if (!ex[j] && p[j].size()) {
        int y = S[j].count();
        if (y < mn) mn = y, x = j;
      }
    if (x == -1) return puts("NO"), void();
    ex[x] = 1;
    int y = *p[x].begin();
    p[x].clear();
    eu.push_back(x), ev.push_back(y);
    for (int j = 0; j < m; j++)
      if (S[x][j]) S[x][j] = 0, --c[j];
    bool reb = 0;
    for (int j = 0; j < m; j++)
      if (c[j] == 1) {
        S[y][j] = 0, c[j] = 0, reb = 1;
      }
    for (int j = 0; j < n; j++)
      if (p[j].find(x) != p[j].end()) p[j].erase(x);
    for (int j = 0; j < n; j++)
      if (!ex[j] && j != y && (S[j] & S[y]) == S[y]) p[y].insert(j);
  }
  puts("YES");
  for (int i = 0; i + 1 < n; i++) cout << eu[i] + 1 << ' ' << ev[i] + 1 << '\n';
}
int main() {
  cin >> T;
  while (T--) {
    Main();
    for (int i = 0; i < n; i++) S[i].reset();
    for (int i = 0; i < m; i++) c[i] = 0;
    for (int i = 0; i < n; i++) p[i].clear();
  }
  return 0;
}
