#include <bits/stdc++.h>
using namespace std;
const long long int N = 100010;
const long long int MOD = 1000 * 1000 * 1000 + 7;
long long int mod(long long int n) { return (n % MOD + MOD) % MOD; }
int vis[1000010];
vector<int> v[1000010];
vector<int> newGraph[1000010];
int par[1000010];
set<int> connected;
void dfs(int node) {
  vis[node] = 1;
  for (int child : v[node]) {
    if (vis[child] == 0) dfs(child);
  }
}
void bfs(int node) {
  queue<int> q;
  q.push(node);
  vis[node] = 1;
  vis[1] = 0;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int child : v[curr]) {
      if (vis[child] == 0) {
        newGraph[curr].push_back(child), newGraph[child].push_back(curr);
        vis[child] = 1;
        if (child != 1) q.push(child);
        if (child == 1) {
          connected.insert(curr);
        }
      }
    }
  }
}
void new_bfs(int node) {
  queue<int> q;
  q.push(node);
  vis[node] = 1;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int child : newGraph[curr]) {
      if (vis[child] == 0) {
        vis[child] = 1;
        cout << curr << " " << child << endl;
        q.push(child);
      }
    }
  }
}
void solve() {
  int n, m, d;
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int cc = 0;
  vis[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (vis[i] == 0) {
      dfs(i), cc++;
    }
  }
  if (d < cc || d > v[1].size()) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  for (int i = 1; i <= n; i++) vis[i] = 0;
  for (int i = 2; i <= n; i++) {
    if (vis[i] == 0) {
      bfs(i);
    }
  }
  int rem = d - newGraph[1].size();
  for (int child : v[1]) {
    if (rem == 0) break;
    if (connected.find(child) == connected.end()) {
      newGraph[1].push_back(child), newGraph[child].push_back(1);
      rem--;
    }
  }
  for (int i = 1; i <= n; i++) {
    vis[i] = 0;
  }
  new_bfs(1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  for (int i = 0; i < T; i++) solve();
}
