#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
int par[MAX];
vector<int> adj[MAX];
int Find(int n) {
  if (par[n] == n) return n;
  return par[n] = Find(par[n]);
}
int fr[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    fr[u]++;
    fr[v]++;
  }
  for (int i = 1; i <= n; i++) par[i] = i;
  int mx = 0, root = -1;
  for (int i = 1; i <= n; i++) {
    if (fr[i] > mx) {
      mx = fr[i];
      root = i;
    }
  }
  for (auto i : adj[root]) {
    int uu = Find(par[root]), vv = Find(par[i]);
    if (uu != vv) {
      if (uu > vv) swap(uu, vv);
      par[uu] = vv;
      cout << root << " " << i << endl;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (auto j : adj[i]) {
      int uu = Find(par[i]), vv = Find(par[j]);
      if (uu != vv) {
        if (uu > vv) swap(uu, vv);
        par[uu] = vv;
        cout << i << " " << j << endl;
      }
    }
  }
}
