#include <bits/stdc++.h>
using namespace std;
vector<int> v[200009];
vector<pair<int, int> > va, vv;
int p[200009];
int fnd(int x) {
  if (p[x] == x) return x;
  return p[x] = fnd(p[x]);
}
void un(int x, int y) {
  x = fnd(x);
  y = fnd(y);
  p[x] = y;
}
int main() {
  for (int i = 1; i <= 200000; i++) p[i] = i;
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    vv.push_back(make_pair(x, y));
  }
  int ans = 0, nd;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() > ans) ans = v[i].size(), nd = i;
  }
  for (auto x : v[nd]) {
    va.push_back(make_pair(nd, x));
    un(nd, x);
  }
  for (auto x : vv) {
    if (fnd(x.first) != fnd(x.second)) {
      va.push_back(make_pair(x.first, x.second));
      un(x.first, x.second);
    }
  }
  for (auto x : va) cout << x.first << " " << x.second << "\n";
}
