#include <bits/stdc++.h>
using namespace std;
inline int myrand(int l, int r) {
  int ret = rand();
  ret <<= 15;
  ret ^= rand();
  if (ret < 0) ret = -ret;
  ret %= (r - l + 1);
  ret += l;
  return ret;
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
using min_pq = std::priority_queue<T, vector<T>, greater<T> >;
const int maxn = 2e5 + 5;
int n, m;
vector<int> g[maxn];
int vis[maxn];
vector<pair<int, int> > ans;
int32_t main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  int node = 1;
  for (int i = 1; i <= n; i++) {
    if (g[node].size() < g[i].size()) node = i;
  }
  vis[node] = 1;
  queue<int> Q;
  for (int v : g[node]) {
    vis[v] = 1;
    Q.push(v);
    ans.emplace_back(node, v);
  }
  while (Q.size()) {
    int u = Q.front();
    Q.pop();
    for (int v : g[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        Q.push(v);
        ans.emplace_back(u, v);
      }
    }
  }
  for (pair<int, int> x : ans) {
    cout << x.first << ' ' << x.second << '\n';
  }
}
