#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int mxN = 2e5 + 5;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
vector<int> g[mxN];
int deg[mxN], vis[mxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[v].push_back(u);
    g[u].push_back(v);
    deg[u]++, deg[v]++;
  }
  int bst = -1;
  for (int i = 0; i < (int)(n); i++)
    if (bst == -1 || deg[bst] < deg[i]) bst = i;
  assert(bst != -1);
  queue<int> q;
  q.push(bst);
  vector<pair<int, int> > ans;
  vis[bst] = 1;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int u : g[cur])
      if (!vis[u]) {
        vis[u] = 1;
        ans.push_back({cur, u});
        q.push(u);
      }
  }
  for (pair<int, int> x : ans)
    cout << x.first + 1 << " " << x.second + 1 << endl;
  return 0;
}
