#include <bits/stdc++.h>
using namespace std;
int anc[200007];
int sz[200007];
int x[200005], y[200005];
vector<int> g[200005];
int get_set(int v) {
  if (v == anc[v]) {
    return v;
  }
  return anc[v] = get_set(anc[v]);
}
void unite_sets(int u, int v) {
  u = get_set(u);
  v = get_set(v);
  if (u == v) {
    return;
  }
  if (sz[u] < sz[v]) {
    swap(u, v);
  }
  sz[u] = sz[u] + sz[v];
  anc[v] = u;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    g[x[i]].push_back(y[i]);
    g[y[i]].push_back(x[i]);
  }
  for (int i = 0; i <= n; i++) {
    sz[i] = 1;
    anc[i] = i;
  }
  int mx = 0;
  int z = 1;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() > mx) {
      mx = g[i].size();
      z = i;
    }
  }
  for (int i = 0; i < g[z].size(); i++) {
    if (get_set(z) != get_set(g[z][i])) {
      unite_sets(z, g[z][i]);
      cout << z << " " << g[z][i] << endl;
    }
  }
  for (int i = 0; i < m; i++) {
    if (get_set(x[i]) != get_set(y[i])) {
      unite_sets(x[i], y[i]);
      cout << x[i] << " " << y[i] << endl;
    }
  }
  return 0;
}
