#include <bits/stdc++.h>
using namespace std;
struct UF {
  int n;
  vector<int> parent, rank;
  UF(int n_ = 0) : n(n_), parent(n_), rank(n_, 1) {
    for (int i = 0; i < n_; i++) parent[i] = i;
  }
  int find(int a) { return parent[a] != a ? parent[a] = find(parent[a]) : a; }
  bool same(int a, int b) { return find(a) == find(b); }
  bool unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (rank[a] < rank[b]) {
      parent[a] = b;
      rank[b] += rank[a];
    } else {
      parent[b] = a;
      rank[a] += rank[b];
    }
    return true;
  }
  int size(int a) { return rank[find(a)]; }
};
int N, M;
vector<int> G[2 << 17];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int mx = 1;
  for (int i = 1; i <= N; i++)
    if (G[i].size() > G[mx].size()) mx = i;
  UF uf(N + 1);
  for (int v : G[mx]) {
    uf.unite(mx, v);
    printf("%d %d\n", mx, v);
  }
  for (int i = 1; i <= N; i++) {
    for (int j : G[i])
      if (uf.unite(i, j)) printf("%d %d\n", i, j);
  }
}
