#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v(200000);
int vis[200000] = {0};
int vis1[200000] = {0};
vector<pair<int, int>> ans;
void dfs(int ci) {
  vis1[ci] = 1;
  for (auto x : v[ci]) {
    if (vis1[x] == 1 || x == 0) continue;
    dfs(x);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int l = 0;
  for (auto x : v[0]) {
    if (v[x].size() == 1) l++;
  }
  if ((int)v[0].size() < k || l > k) {
    cout << "NO";
    return 0;
  }
  queue<int> q;
  vis[0] = 1;
  l = 0;
  for (auto x : v[0]) {
    if (v[x].size() == 1) {
      ans.push_back({0, x});
      l++;
      vis[x] = 1;
      q.push(x);
      if (l == k) break;
    }
  }
  for (auto x : v[0]) {
    if (l == k) break;
    if (vis[x] == 1 || vis1[x] == 1) continue;
    ans.push_back({0, x});
    q.push(x);
    vis[x] = 1;
    dfs(x);
    l++;
  }
  for (auto x : v[0]) {
    if (l == k) break;
    if (vis[x] == 1) continue;
    ans.push_back({0, x});
    vis[x] = 1;
    q.push(x);
    l++;
  }
  while (q.size() > 0) {
    int ci = q.front();
    q.pop();
    for (auto x : v[ci]) {
      if (vis[x] == 1) continue;
      ans.push_back({ci, x});
      vis[x] = 1;
      q.push(x);
    }
  }
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES\n";
  for (auto x : ans) cout << x.first + 1 << " " << x.second + 1 << "\n";
}
