#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200 * 1000 + 10;
int n, m, mx, root, par[MAXN];
bool mark[MAXN];
vector<int> adj[MAXN];
queue<int> q;
void bfs(int root) {
  q.push(root);
  while (!q.empty()) {
    int v = q.front();
    mark[v] = 1;
    q.pop();
    for (auto u : adj[v])
      if (!mark[u]) {
        q.push(u);
        if (par[u] == -1) par[u] = v;
      }
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  for (int i = 0; i < MAXN; i++) par[i] = -1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  for (int i = 0; i < n; i++)
    if ((int)adj[i].size() > mx) mx = (int)adj[i].size(), root = i;
  bfs(root);
  for (int i = 0; i < n; i++)
    if (i != root) cout << i + 1 << ' ' << par[i] + 1 << endl;
  return 0;
}
