#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> kraw[N];
int degree[N];
bool odw[N];
int n, m;
void bfs(int s) {
  odw[s] = true;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int v : kraw[x]) {
      if (odw[v]) continue;
      cout << x << " " << v << "\n";
      odw[v] = true;
      q.push(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  int max_degree = 0, w = 0;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    kraw[u].push_back(v);
    kraw[v].push_back(u);
    degree[u]++;
    degree[v]++;
    if (degree[u] > max_degree) {
      max_degree = degree[u];
      w = u;
    }
    if (degree[v] > max_degree) {
      max_degree = degree[v];
      w = v;
    }
  }
  bfs(w);
}
