#include <bits/stdc++.h>
using namespace std;
long n, m, i, x, y, ma, k, q[1000013], l, r, t;
vector<long> a[1000013];
bool f[1000013];
void loang() {
  l = 1;
  r = 1;
  q[1] = k;
  t = n - 1;
  f[k] = true;
  while (l <= r) {
    long u = q[l];
    l++;
    for (long i = 0; i < a[u].size(); i++) {
      long v = a[u][i];
      if (t == 0) return;
      if (f[v] == false) {
        cout << u << " " << v << endl;
        t--;
        r++;
        q[r] = v;
        f[v] = true;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
    if (a[x].size() > ma) {
      ma = a[x].size();
      k = x;
    }
    if (a[y].size() > ma) {
      ma = a[y].size();
      k = y;
    }
  }
  loang();
}
