#include <bits/stdc++.h>
const long long N = 500005;
const long long mod = 1e9 + 7;
using namespace std;
std::vector<long long> adj[N];
std::vector<bool> vis(N);
void solve() {
  long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  x = 0;
  for (int i = 1; i <= n; ++i) {
    if (x < adj[i].size()) {
      x = adj[i].size();
      y = i;
    }
  }
  std::vector<pair<long long, long long> > v;
  queue<long long> nodes;
  nodes.push(y);
  vis[y] = 1;
  while (!nodes.empty()) {
    x = nodes.front();
    nodes.pop();
    for (auto i : adj[x]) {
      if (!vis[i]) {
        vis[i] = 1;
        nodes.push(i);
        v.push_back({x, i});
      }
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i].first << " " << v[i].second << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
