#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n + 1, vector<int>());
  int i;
  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  int maxi = 0, idx;
  for (i = 1; i <= n; i++)
    if (a[i].size() > maxi) {
      maxi = a[i].size();
      idx = i;
    }
  queue<pair<int, int> > q;
  vector<int> v(n + 1, 0);
  for (auto x : a[idx]) q.push({idx, x});
  v[idx] = 1;
  while (!q.empty()) {
    int bef = q.front().first;
    int start = q.front().second;
    q.pop();
    if (v[start]) continue;
    v[start] = 1;
    cout << bef << " " << start << endl;
    for (auto x : a[start])
      if (!v[x]) q.push({start, x});
  }
}
