#include <bits/stdc++.h>
using namespace std;
long long n, m, d;
vector<list<long long>> adjList((long long)(2e5 + 10));
long long fa[(long long)(2e5 + 10)] = {};
void dfs(long long nd) {
  for (long long i : adjList[nd]) {
    if (!fa[i]) {
      if (nd == 1) d--;
      fa[i] = nd;
      dfs(i);
    }
  }
}
void solve() {
  cin >> n >> m >> d;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    adjList[a].push_back(b);
    adjList[b].push_back(a);
  }
  if (adjList[1].size() < d) {
    cout << "NO" << endl;
    return;
  }
  fa[1] = -1;
  dfs(1);
  if (d < 0) {
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
  for (long long i : adjList[1]) {
    if (d and fa[i] != 1) {
      d--;
      fa[i] = 1;
    }
  }
  for (long long i = 2; i <= n; i++) cout << fa[i] << " " << i << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  long long t_c = 1;
  while (t_c--) solve();
}
