#include <bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
template <class T>
using matrix = std::vector<std::vector<T>>;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  const int N = 2 * 100 * 1000 + 2;
  std::vector<int> a[N];
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  std::vector<bool> visited(n, false);
  std::function<void(int)> dfs = [&](int v) {
    visited[v] = true;
    for (int u : a[v]) {
      if (!visited[u]) dfs(u);
    }
  };
  int cnt = 0;
  std::vector<int> must_have;
  std::vector<bool> used(n, false);
  visited[0] = true;
  for (int v : a[0]) {
    if (!visited[v]) {
      cnt++;
      dfs(v);
      must_have.push_back(v);
    }
  }
  if (cnt > k || a[0].size() < k) {
    cout << "NO\n";
    return 0;
  }
  std::vector<int> p(n), rk(n, 0);
  for (int i = 0; i < n; i++) p[i] = i;
  std::function<int(int)> get = [&](int v) {
    return p[v] == v ? v : p[v] = get(p[v]);
  };
  std::function<bool(int, int)> unite = [&](int a, int b) {
    a = get(a);
    b = get(b);
    if (a == b) return false;
    if (rk[a] < rk[b]) std::swap(a, b);
    p[b] = a;
    if (rk[a] == rk[b]) rk[a]++;
    return true;
  };
  cout << "YES\n";
  for (int v : must_have) {
    assert(unite(0, v));
    cout << 1 << " " << 1 + v << "\n";
    used[v] = true;
    k--;
  }
  for (int v : a[0]) {
    if (k > 0 && !used[v]) {
      assert(unite(0, v));
      cout << 1 << " " << 1 + v << "\n";
      k--;
    }
  }
  for (int v = 1; v < n; v++) {
    for (int u : a[v]) {
      if (u != 0 && unite(v, u)) {
        cout << 1 + v << " " << 1 + u << "\n";
      }
    }
  }
  return 0;
}
