#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = (long long)1e6 + 6;
const long double EPS = 1e-9;
const long long INF = (long long)1e18 + 18;
const long long mod = (long long)1e9 + 7;
long long n, m, D, parent[maxn], used[maxn], marked[maxn];
long long already = 0;
vector<long long> g[maxn];
void dfs(long long u, long long p) {
  parent[u] = p;
  used[u] = 1;
  for (long long v : g[u]) {
    if (used[v] == 1) continue;
    if (u == 0) {
      already++;
      marked[v] = 1;
    }
    dfs(v, u);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> D;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(parent, -1, sizeof(parent));
  dfs(0, -1);
  for (long long to : g[0]) {
    if (already == D) break;
    if (marked[to] == 0) {
      parent[to] = 0;
      already++;
    }
  }
  if (already != D) {
    cout << "NO" << '\n';
  } else {
    cout << "YES" << '\n';
    for (long long i = 1; i < n; i++) {
      cout << i + 1 << " " << parent[i] + 1 << '\n';
    }
  }
  return 0;
}
