#include <bits/stdc++.h>
using namespace std;
int P[2][200001], G[200001];
int get(int x, int j) { return x == P[j][x] ? x : P[j][x] = get(P[j][x], j); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, d, u, v;
  cin >> n >> m >> d;
  vector<pair<int, int> > ones, rest, fin;
  for (int i = 1; i <= n; ++i) P[0][i] = P[1][i] = i;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    if (u > v) swap(u, v);
    u == 1 ? ones.push_back({u, v}) : rest.push_back({u, v});
  }
  for (auto e : rest) {
    int px = get(e.first, 0), py = get(e.second, 0);
    if (px != py) P[0][px] = py;
  }
  for (auto e : ones) {
    int px = get(e.first, 0), py = get(e.second, 0);
    if (px != py) {
      fin.push_back({e.first, e.second});
      P[0][px] = py;
      P[1][get(e.first, 1)] = get(e.second, 1);
    }
  }
  d -= fin.size();
  if (d < 0) {
    cout << "NO";
    return 0;
  }
  for (auto e : ones) {
    if (d == 0) break;
    int px = get(e.first, 1), py = get(e.second, 1);
    if (px != py) {
      fin.push_back({e.first, e.second});
      P[1][get(e.first, 1)] = get(e.second, 1);
      --d;
    }
  }
  if (d) {
    cout << "NO";
    return 0;
  }
  for (auto e : rest) {
    int px = get(e.first, 1), py = get(e.second, 1);
    if (px != py) P[1][px] = py, fin.push_back({e.first, e.second});
  }
  cout << "YES\n";
  for (auto j : fin) cout << j.first << " " << j.second << '\n';
}
