#include <bits/stdc++.h>
using namespace std;
int n, k = 0;
int a[200001], pre[200001];
struct node {
  int x, y;
} b[200001];
int find(int x) {
  int r = x;
  while (r != pre[r]) r = pre[r];
  int i = x, j;
  while (i != r) {
    j = pre[i];
    pre[i] = r;
    i = j;
  }
  return r;
}
int main() {
  int n, m, x, y, maxx = 0, ma, sum = 0;
  memset(a, 0, sizeof(a));
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= n; i++) pre[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &b[i].x, &b[i].y);
    a[b[i].x]++;
    a[b[i].y]++;
  }
  for (int i = 1; i <= n; i++) {
    if (maxx < a[i]) {
      maxx = a[i];
      ma = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (sum == n - 1) return 0;
    if (b[i].x == ma || b[i].y == ma) {
      printf("%d %d\n", b[i].x, b[i].y);
      pre[b[i].x] = ma, pre[b[i].y] = ma;
      sum++;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (b[i].x != ma && b[i].y != ma) {
      int fx = find(b[i].x), fy = find(b[i].y);
      if (fx != fy) {
        printf("%d %d\n", b[i].x, b[i].y);
        pre[fy] = fx;
        sum++;
      }
    }
    if (sum == n - 1) return 0;
  }
}
