#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> g[N];
int deg[N];
bool mark[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  int st = -1, Max = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i] > Max) {
      Max = deg[i];
      st = i;
    }
  }
  mark[st] = 1;
  queue<int> que;
  que.push(st);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto &cur : g[node]) {
      if (!mark[cur]) {
        cout << node << ' ' << cur << '\n';
        mark[cur] = 1;
        que.push(cur);
      }
    }
  }
  return 0;
}
