#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g;
vector<bool> used;
vector<pair<long long, long long>> ans;
void dfs(long long v) {
  used[v] = true;
  for (auto c : g[v]) {
    if (!used[c]) {
      ans.push_back({v + 1, c + 1});
      dfs(c);
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  g.resize(n);
  used.assign(n, false);
  for (long long i = 0; i < m; i++) {
    long long v, to;
    cin >> v >> to;
    v--;
    to--;
    g[v].push_back(to);
    g[to].push_back(v);
  }
  long long maxpow = 0;
  long long start = 0;
  for (long long i = 0; i < n; i++) {
    if (g[i].size() > maxpow) {
      maxpow = g[i].size();
      start = i;
    }
  }
  used[start] = true;
  for (auto c : g[start]) {
    ans.push_back({start + 1, c + 1});
    used[c] = true;
  }
  for (auto c : g[start]) {
    dfs(c);
  }
  for (auto c : ans) {
    cout << c.first << ' ' << c.second << endl;
  }
  return 0;
}
