#include <bits/stdc++.h>
using namespace std;
long long color[200005] = {0};
long long visited[200005] = {0};
vector<long long> graph[200005];
long long max1 = 1, node1;
int main() {
  long long n, m, i, u, v, j;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  for (i = 1; i <= n; i++) {
    if (graph[i].size() >= max1) {
      max1 = graph[i].size();
      node1 = i;
    }
  }
  queue<long long> q;
  q.push(node1);
  visited[node1] = 1;
  while (!q.empty()) {
    long long a = q.front();
    for (i = 0; i < graph[a].size(); i++) {
      long long node = graph[a][i];
      if (!visited[node]) {
        visited[node] = visited[node] + 1;
        if (visited[node] <= 1) {
          cout << node << " " << a << endl;
          q.push(node);
        }
      }
    }
    q.pop();
  }
  return 0;
}
