#include <bits/stdc++.h>
using namespace std;
vector<int> graph[200005];
int par[200005];
bool visited[200005];
bool ar[200005];
void dfs(int curr) {
  if (graph[curr].size() == 0) return;
  for (int i = 0; i < graph[curr].size(); i++) {
    if (!visited[graph[curr][i]]) {
      if (!ar[graph[curr][i]]) {
        par[graph[curr][i]] = curr;
        ar[graph[curr][i]] = 1;
      }
    }
  }
  for (int i = 0; i < graph[curr].size(); i++) {
    if (!visited[graph[curr][i]]) {
      visited[graph[curr][i]] = 1;
      dfs(graph[curr][i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(visited, 0, sizeof(visited));
  memset(par, 0, sizeof(par));
  memset(ar, 0, sizeof(ar));
  long long n, m;
  cin >> n >> m;
  int root = 1;
  int maxi = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    if (graph[u].size() > maxi) {
      maxi = graph[u].size();
      root = u;
    }
    graph[v].push_back(u);
    if (graph[v].size() > maxi) {
      maxi = graph[v].size();
      root = v;
    }
  }
  visited[root] = 1;
  par[root] = 0;
  dfs(root);
  for (int i = 1; i <= n; i++) {
    if (par[i] != 0) cout << i << " " << par[i] << endl;
  }
}
