#include <bits/stdc++.h>
using namespace std;
int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
}
vector<long long int> tree[200003];
vector<long long int> v[200003];
bool vis[200003];
void bfs(long long int n) {
  vis[n] = true;
  queue<long long int> q;
  q.push(n);
  while (!q.empty()) {
    long long int p = q.front();
    q.pop();
    for (auto to : v[p]) {
      if (vis[to] != true) {
        tree[p].push_back(to);
        vis[to] = true;
        q.push(to);
      }
    }
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  while (m--) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  long long int ma = 1;
  for (long long int i = 1; i <= n; i++) {
    if ((long long int)v[i].size() > (long long int)v[ma].size()) ma = i;
  }
  bfs(ma);
  for (long long int i = 1; i <= n; i++) {
    for (auto j : tree[i]) cout << i << " " << j << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
