#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> g[maxn];
vector<int> parent(maxn);
void make_set() {
  for (int i = 0; i < maxn; i++) parent[i] = i;
}
int find_set(int a) {
  if (a == parent[a]) return parent[a];
  return parent[a] = find_set(parent[a]);
}
void make_union(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) parent[b] = a;
}
void solve() {
  int n, m, a, b;
  cin >> n >> m;
  vector<pair<int, int>> inp, res;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    inp.push_back({a, b});
  }
  int node, mx = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() > mx) {
      mx = g[i].size();
      node = i;
    }
  }
  for (int i = 0; i < g[node].size(); i++) {
    res.push_back({node, g[node][i]});
    make_union(node, g[node][i]);
  }
  for (int i = 0; i < inp.size(); i++) {
    int a = inp[i].first;
    int b = inp[i].second;
    if (find_set(a) != find_set(b)) {
      res.push_back({a, b});
      make_union(a, b);
    }
  }
  for (int i = 0; i < res.size(); i++)
    cout << res[i].first << " " << res[i].second << "\n";
}
int main() {
  make_set();
  solve();
  return 0;
}
