#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 1;
int size[N];
int parent[N];
int Root(int x) {
  while (x != parent[x]) {
    parent[x] = parent[parent[x]];
    x = parent[x];
  }
  return x;
}
void Union(int x, int y) {
  int root_x = Root(x);
  int root_y = Root(y);
  if (root_x != root_y) {
    if (size[root_x] > size[root_y]) {
      parent[root_y] = root_x;
      size[root_x] += size[root_y];
    } else {
      parent[root_x] = root_y;
      size[root_y] += size[root_x];
    }
    cout << x << " " << y << endl;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int arr[200006] = {0};
  int x[m], y[m];
  for (int i = 1; i < N; i++) size[i] = 1;
  for (int i = 1; i < N; i++) parent[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    arr[x[i]]++;
    arr[y[i]]++;
  }
  int max = 0;
  int v;
  for (int i = 1; i < 200006; i++) {
    if (max < arr[i]) {
      max = arr[i];
      v = i;
    }
  }
  for (int i = 0; i < m; i++) {
    if (x[i] == v || y[i] == v) {
      Union(x[i], y[i]);
    }
  }
  for (int i = 0; i < m; i++) {
    if (x[i] != v && y[i] != v) Union(x[i], y[i]);
  }
}
