#include <bits/stdc++.h>
using namespace std;
list<long long> adjList[(long long)(2e5 + 10)];
vector<vector<long long>> tree;
bitset<(long long)(2e5 + 10)> vis;
long long deg[(long long)(2e5 + 10)];
vector<pair<vector<long long>, vector<long long>>> exEd;
void dfs(long long nd, long long par) {
  vis[nd] = true;
  bool inc = false;
  for (long long i : adjList[nd]) {
    if (i != par) {
      if (i == 1) {
        exEd.push_back({{1, nd}, {par, nd}});
        inc = true;
      } else if (!vis[i])
        dfs(i, nd);
    }
  }
  if (!inc) tree.push_back({nd, par});
}
void solve() {
  long long n, m, d;
  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);
    deg[a]++, deg[b]++;
  }
  if (deg[1] < d) {
    cout << "NO" << endl;
    return;
  }
  long long cnt = 0;
  for (long long i : adjList[1]) {
    if (!vis[i]) {
      cnt++;
      dfs(i, 1);
    }
  }
  if (cnt > d) {
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
  for (long long i = 0; i < exEd.size(); i++) {
    if (i < d - cnt)
      tree.push_back(exEd[i].first);
    else
      tree.push_back(exEd[i].second);
  }
  for (vector<long long> &v : tree) cout << v[0] << " " << v[1] << 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();
}
