#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n, m, a, b, root = 0, mx = -1, temp;
  cin >> n >> m;
  vector<long long> adj[n + 5], cnt(n + 5), vis(n + 5);
  for (long long i = 1; i <= m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    cnt[a]++;
    cnt[b]++;
    if (cnt[a] > mx) {
      root = a;
      mx = cnt[a];
    }
    if (cnt[b] > mx) {
      root = b;
      mx = cnt[b];
    }
  }
  queue<long long> q;
  q.push(root);
  vis[root] = 1;
  while (!q.empty()) {
    temp = q.front();
    q.pop();
    for (auto it : adj[temp]) {
      if (!vis[it]) {
        vis[it] = 1;
        q.push(it);
        cout << temp << " " << it << "\n";
      }
    }
  }
  return 0;
}
