#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 40;
const int inf = 0x3fffffff;
void read(int &x) {
  char ch;
  bool flag = 0;
  for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
       ch = getchar())
    ;
  for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())
    ;
  x *= 1 - 2 * flag;
}
int deg[maxn];
int fa[maxn];
int fin(int x) {
  if (x == fa[x]) return x;
  return fa[x] = fin(fa[x]);
}
struct inof {
  int l, r;
} p[maxn * 10];
int t = 0;
bool cmp(inof a, inof b) {
  if (deg[a.l] != deg[b.l]) return deg[a.l] > deg[b.l];
  return a.l < b.l;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    p[t].l = l, p[t].r = r;
    t++;
    p[t].r = l, p[t].l = r;
    t++;
    deg[l]++, deg[r]++;
  }
  sort(p, p + t, cmp);
  int top = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 0; i < t; i++) {
    int x = p[i].l, y = p[i].r;
    x = fin(x), y = fin(y);
    if (x == y) continue;
    fa[x] = y;
    top++;
    printf("%d %d\n", p[i].l, p[i].r);
    if (top == n - 1) break;
  }
  return 0;
}
