#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
int n, m, res, D;
int canhcau[maxn], dd[maxn];
bool color[maxn];
vector<int> a[maxn], b[maxn];
vector<pair<int, int> > kq;
void bfs(int m) {
  queue<int> q;
  q.push(m);
  dd[m] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i <= b[u].size() - 1; i++) {
      int v = b[u][i];
      if (dd[v] == 0) {
        dd[v] = 1;
        q.push(v);
        kq.push_back(pair<int, int>(u, v));
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i <= kq.size() - 1; i++)
    cout << kq[i].first << " " << kq[i].second << '\n';
}
void dfs(int u) {
  for (int i = 0; i <= a[u].size() - 1; i++) {
    int v = a[u][i];
    if (color[v] == 0 && v != 1) {
      color[v] = res;
      b[u].push_back(v);
      b[v].push_back(u);
      dfs(v);
    }
  }
}
int dem_tplt() {
  res = 0;
  for (int x = 0; x <= a[1].size() - 1; x++) {
    int i = a[1][x];
    if (color[i] == 0) {
      res++;
      color[i] = res;
      b[1].push_back(i);
      b[i].push_back(1);
      canhcau[i] = 1;
      dfs(i);
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> D;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  if (D > a[1].size()) {
    cout << "NO";
    return (0);
  }
  int so_tplt = dem_tplt();
  if (so_tplt > D) {
    cout << "NO";
    return (0);
  }
  int x = D - so_tplt;
  if (x > 0) {
    for (int i = 0; i <= a[1].size() - 1; i++) {
      int v = a[1][i];
      if (canhcau[v] == 0) {
        b[1].push_back(v);
        b[v].push_back(1);
      }
      if (b[1].size() == D) break;
    }
  }
  bfs(1);
}
