#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long int par[maxn];
long long int a[maxn];
int cmp[maxn];
int l[maxn];
int r[maxn];
vector<int> t[maxn];
set<pair<int, pair<int, int> > > p;
int get_par(int v) {
  if (par[v] == -1) {
    return v;
  }
  return par[v] = get_par(par[v]);
}
void merge(int v, int k) {
  if (get_par(v) == get_par(k)) {
    return;
  }
  par[get_par(k)] = get_par(v);
  return;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(par, -1, sizeof(par));
  int n;
  int m;
  cin >> n >> m;
  int u = 0;
  int j = 0;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    cmp[l[i]]++;
    cmp[r[i]]++;
    if (cmp[l[i]] > u) {
      u = cmp[l[i]];
      j = l[i];
    }
    if (cmp[r[i]] > u) {
      u = cmp[r[i]];
      j = r[i];
    }
    t[l[i]].push_back(r[i]);
    t[r[i]].push_back(l[i]);
    p.insert({1, {l[i], r[i]}});
  }
  for (int i = 0; i < t[j].size(); i++) {
    cout << j << " " << t[j][i] << endl;
    merge(j, t[j][i]);
  }
  long long int res = 0;
  while (p.size() != 0) {
    long long int y = p.begin()->first;
    int u = p.begin()->second.first;
    int v = p.begin()->second.second;
    if (get_par(u) != get_par(v)) {
      cout << v << " " << u << endl;
      merge(u, v);
    }
    p.erase(p.begin());
  }
  return 0;
}
