#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int inf = 1e9 + 1;
int n, m, k;
vector<int> v[N];
int p[N];
int found[N]{0};
void bfs(int u) {
  found[u] = 1;
  for (int i : v[u]) {
    if (!found[i]) {
      p[i] = u;
      if (u == 1) k--;
      bfs(i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    if (v[1].size() < k) {
      cout << ("NO") << '\n';
      return 0;
    }
    bfs(1);
    if (k < 0) {
      cout << ("NO") << '\n';
      return 0;
    }
    cout << ("YES") << '\n';
    for (int i : v[1]) {
      if (k && p[i] != 1) {
        p[i] = 1;
        k--;
      }
    }
    for (int i = 2; i <= n; i++) {
      cout << (p[i]) << " " << (i) << '\n';
    }
  }
  return 0;
}
