#include <bits/stdc++.h>
using namespace std;
struct unionfind {
  vector<int> P;
  unionfind(int n) : P(n) {
    for (int i = 0; i < n; i++) {
      P[i] = i;
    }
  }
  int root(int x) {
    if (P[x] == x) return x;
    return P[x] = root(P[x]);
  }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    P[y] = x;
    return true;
  }
};
int main() {
  int N, M, D;
  cin >> N >> M >> D;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  unionfind uf(N);
  for (int i = 1; i < N; i++) {
    for (int j : G[i])
      if (j != 0) {
        uf.merge(i, j);
      }
  }
  vector<int> es;
  for (int j : G[0]) {
    if (uf.merge(0, j)) {
      es.emplace_back(j);
    }
  }
  unionfind uf2(N);
  if (es.size() > D) {
    cout << "NO" << endl;
    return 0;
  }
  vector<int> ansu, ansv;
  for (int e : es) {
    if (uf2.merge(0, e)) {
      ansu.push_back(0);
      ansv.push_back(e);
      D--;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j : G[i])
      if (i < j) {
        if (i == 0 && D == 0) break;
        if (uf2.merge(i, j)) {
          if (i == 0) D--;
          ansu.push_back(i);
          ansv.push_back(j);
        }
      }
  }
  if (D > 0) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int i = 0; i < ansu.size(); i++) {
    printf("%d %d\n", ansu[i] + 1, ansv[i] + 1);
  }
}
