#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<vector<int> > g;
set<pair<int, int> > ans;
vector<int> used;
void bfs(int start) {
  deque<int> st(1, start);
  used[start] = 1;
  while (st.size()) {
    int v = st.front();
    st.pop_front();
    for (int e : g[v]) {
      if (!used[e]) {
        used[e] = 1;
        st.push_back(e);
        ans.insert({min(v, e), max(v, e)});
      }
    }
  }
}
signed main() {
  fast();
  int n, m;
  cin >> n >> m;
  used.resize(n);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int start = 0;
  for (int i = 0; i < n; ++i) {
    if (g[i].size() > g[start].size()) {
      start = i;
    }
  }
  bfs(start);
  for (auto e : ans) cout << e.first + 1 << " " << e.second + 1 << '\n';
  return 0;
}
