#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1e2;
vector<int> mp[maxn];
int vis[maxn] = {0};
int deg[maxn] = {0};
void bfs(int s) {
  vis[s] = 1;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < mp[now].size(); ++i) {
      int to = mp[now][i];
      if (!vis[to]) {
        vis[to] = 1;
        printf("%d %d\n", now, to);
        q.push(to);
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int u, v;
  int aimp, mdeg = -1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
    ++deg[u];
    ++deg[v];
    if (++deg[u] > mdeg) mdeg = deg[u], aimp = u;
    if (++deg[v] > mdeg) mdeg = deg[v], aimp = v;
  }
  bfs(aimp);
  return 0;
}
