#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const double pi = acos(-1);
const int inf = 1 << 30;
const int mod = 1e9 + 7;
int n, m;
vector<pair<int, int> > G[maxn];
int ind[maxn], Max = 0;
int vis[maxn], ans[maxn];
int u[maxn], v[maxn];
int cnt = 0;
void Bfs(int x) {
  queue<int> qwe;
  qwe.push(x);
  vis[x] = 1;
  while (!qwe.empty()) {
    int now = qwe.front();
    qwe.pop();
    for (int i = 0; i < G[now].size(); i++) {
      pair<int, int> s = G[now][i];
      if (vis[s.first]) continue;
      vis[s.first] = 1;
      ans[++cnt] = s.second;
      qwe.push(s.first);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &u[i], &v[i]);
    ind[u[i]]++, ind[v[i]]++;
    Max = max(Max, ind[u[i]]);
    Max = max(Max, ind[v[i]]);
    G[u[i]].push_back(pair<int, int>(v[i], i));
    G[v[i]].push_back(pair<int, int>(u[i], i));
  }
  for (int i = 1; i <= n; i++) {
    if (ind[i] == Max) {
      Bfs(i);
      break;
    }
  }
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", u[ans[i]], v[ans[i]]);
  return 0;
}
