#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int n, m, d, dr, pre[maxn], rnk[maxn], vis[maxn], flag[maxn];
int e, head[maxn];
struct Edge {
  int from, to;
};
struct E {
  int from, to, next;
} edge[2 * maxn];
queue<int> q;
vector<int> rt;
vector<Edge> oth, ans;
void add_edge(int u, int v) {
  edge[e].from = u;
  edge[e].to = v;
  edge[e].next = head[u];
  head[u] = e++;
}
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rnk[x] > rnk[y]) {
    pre[y] = x;
  } else {
    pre[x] = y;
    if (rnk[x] == rnk[y]) rnk[y]++;
  }
}
void bfs() {
  flag[1] = 1;
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (int i = head[f]; i != -1; i = edge[i].next) {
      int u = edge[i].to;
      if (flag[u]) continue;
      flag[u] = 1;
      ans.push_back(Edge{f, u});
      q.push(u);
    }
  }
}
bool solve() {
  int cnt = 0;
  for (int i = 0; i < oth.size(); i++) {
    int u = oth[i].from, v = oth[i].to;
    if (find(u) == find(v)) continue;
    merge(u, v);
  }
  for (int i = 0; i < dr; i++) {
    if (vis[find(rt[i])]) continue;
    q.push(rt[i]);
    ans.push_back(Edge{1, rt[i]});
    vis[find(rt[i])] = 1;
    flag[rt[i]] = 1;
    cnt++;
  }
  if (cnt > d) return false;
  for (int i = 0; cnt < d && i < dr; i++) {
    if (flag[rt[i]]) continue;
    q.push(rt[i]);
    ans.push_back(Edge{1, rt[i]});
    flag[rt[i]] = 1;
    cnt++;
  }
  bfs();
  for (int i = 1; i <= n; i++)
    if (!flag[i]) return false;
  return true;
}
void init() {
  for (int i = 0; i <= n; i++) {
    pre[i] = i;
    rnk[i] = 0;
    head[i] = -1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> n >> m >> d;
  init();
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    add_edge(a, b);
    add_edge(b, a);
    if (min(a, b) == 1) {
      dr++;
      rt.push_back(max(a, b));
    } else
      oth.push_back(Edge{a, b});
  }
  if (dr < d || !solve()) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].from << ' ' << ans[i].to << endl;
  }
}
