#include <bits/stdc++.h>
using namespace std;
vector<int> a[2000007];
vector<int> deg(2000007, 0);
vector<pair<int, int>> ans;
int n, m;
void bfs(int node) {
  vector<bool> used(n);
  used[node] = true;
  queue<int> q;
  q.push(node);
  while (!q.empty()) {
    int currnode = q.front();
    q.pop();
    for (auto x : a[currnode]) {
      if (used[x]) continue;
      ans.push_back({x, currnode});
      used[x] = true;
      q.push(x);
    }
  }
}
void solve() {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    a[u].push_back(v);
    a[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  int maxnode = 0;
  for (int i = 0; i < n; i++) {
    if (deg[maxnode] < deg[i]) maxnode = i;
  }
  bfs(maxnode);
  for (auto x : ans) {
    cout << x.first + 1 << " " << x.second + 1 << endl;
  }
}
int main() {
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
