#include <bits/stdc++.h>
#pragma GCC optimize "Ofast"
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 2000;
vector<int> e[N];
namespace DSU {
int p[N];
void init(int n) { fill(p, p + n, -1); }
int gp(int x) { return (-1 == p[x]) ? x : (p[x] = gp(p[x])); }
void uni(int x, int y) {
  int cx = gp(x), cy = gp(y);
  if (cx != cy) {
    e[x].push_back(y);
    e[y].push_back(x);
    p[cx] = cy;
  }
}
}  // namespace DSU
const int C = 27;
const int MS = 1 << C;
const int LEN = (N + C - 1) / C;
char popcount[MS];
vector<pair<int, int>> eds[N + 1];
string s[N];
bool in[N + 1];
void precalc() {
  for (int i = 1; i < MS; i <<= 1) {
    for (int j = i; j < i + i; ++j) {
      popcount[j] = popcount[j - i] + 1;
    }
  }
}
int p[N];
int a[N][LEN];
void dfs(int v, int p) {
  ::p[v] = p;
  for (int u : e[v]) {
    if (u != p) {
      dfs(u, v);
    }
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  DSU::init(n);
  for (int i = 0; i < n; ++i) {
    memset(a[i], 0, sizeof(a[i]));
  }
  for (int i = 0; i < m; ++i) {
    cin >> s[i];
    s[i] += '0';
    for (int j = 0; j < n; ++j) {
      a[j][i / C] += (s[i][j] - '0') << (i % C);
      ;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int cur = 0;
      for (int l = 0; l < LEN; ++l) {
        cur += popcount[a[i][l] & a[j][l]];
      }
      eds[cur].emplace_back(i, j);
    }
  }
  for (int i = m; i >= 0; --i) {
    for (auto& [a, b] : eds[i]) {
      DSU::uni(a, b);
    }
  }
  dfs(0, n);
  int badcnt = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (s[i][j] == '1') {
        badcnt += (s[i][p[j]] == '0');
      }
    }
  }
  if (badcnt == m) {
    cout << "YES\n";
    for (int i = 0; i < n; ++i) {
      for (int v : e[i]) {
        if (v > i) {
          cout << i + 1 << " " << v + 1 << "\n";
        }
      }
    }
  } else {
    cout << "NO\n";
  }
  for (int i = 0; i < n; ++i) {
    e[i].clear();
  }
  for (int i = 0; i <= m; ++i) {
    eds[i].clear();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(20);
  precalc();
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
}
