#include <bits/stdc++.h>
using namespace std;
const int maxN = 2018;
vector<int> G[maxN];
bitset<maxN> B[maxN];
tuple<int, int, int> E[maxN * maxN];
int F[maxN];
int find(int a) {
  if (F[a] == a) return a;
  return F[a] = find(F[a]);
}
bool Union(int a, int b) {
  int c = find(a), d = find(b);
  if (c == d) return false;
  F[d] = c;
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    int cnt = -m;
    for (int(i) = (0); (i) < (m); (i)++) {
      static char in[maxN];
      scanf("%s", in + 1);
      for (int(j) = (1); (j) < (n + 1); (j)++)
        if (in[j] == '1') B[j].set(i), cnt++;
    }
    int k = 0;
    for (int(i) = (2); (i) < (n + 1); (i)++)
      for (int(j) = (1); (j) < (i); (j)++)
        E[k++] = make_tuple(-(B[i] & B[j]).count(), i, j);
    sort(E, E + k);
    for (int(i) = (1); (i) < (n + 1); (i)++) F[i] = i;
    for (int(i) = (0); (i) < (k); (i)++) {
      int a, b, c;
      tie(c, a, b) = E[i];
      if (!Union(a, b)) continue;
      cnt += c;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    if (cnt != 0)
      printf("NO\n");
    else {
      printf("YES\n");
      for (int(i) = (1); (i) < (n + 1); (i)++)
        for (int j : G[i])
          if (j < i) printf("%d %d\n", j, i);
    }
    for (int(i) = (1); (i) < (n + 1); (i)++) G[i].resize(0), B[i] &= B[0];
  }
  return 0;
}
