#include <bits/stdc++.h>
using namespace std;
vector<long long int> graph[200005];
bool vis[200005];
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  int max_size = 0, vertex;
  for (int i = 1; i <= n; i++) {
    if (max_size < (int)graph[i].size()) {
      vertex = i;
      max_size = (int)graph[i].size();
    }
  }
  queue<int> q;
  memset(vis, false, sizeof(vis));
  q.push(vertex);
  vis[vertex] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < graph[u].size(); i++) {
      int v = graph[u][i];
      if (!vis[v]) {
        cout << u << " " << v << endl;
        q.push(v);
        vis[v] = true;
      }
    }
  }
}
