#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
vector<int> g[N];
int mark[N];
int maks;
void dfs(int start) {
  mark[start] = 1;
  for (int xt : g[start]) {
    if (!mark[xt]) {
      printf("%d %d\n", start, xt);
      dfs(xt);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (maks < g[i].size()) maks = g[i].size();
  }
  int start;
  for (int i = 1; i <= n; i++) {
    if (maks == g[i].size()) {
      start = i;
      break;
    }
  }
  for (auto xt : g[start]) {
    printf("%d %d\n", xt, start);
    mark[xt] = 1;
  }
  mark[start] = 1;
  for (int xt : g[start]) {
    dfs(xt);
  }
}
