#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v;
long long int indegree[300005];
long long int vis[300005];
long long int parent[300005];
long long int getpar(long long int child) {
  if (parent[child] == child)
    return child;
  else
    return parent[child] = getpar(parent[child]);
}
void merge(long long int v1, long long int v2) {
  parent[getpar(v1)] = getpar(v2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int n, m;
    cin >> n >> m;
    v.resize(m);
    memset(indegree, 0, sizeof(indegree));
    memset(vis, 0, sizeof(vis));
    for (long long int i = 1; i <= n; i++) {
      parent[i] = i;
    }
    for (long long int i = 0; i < m; i++) {
      cin >> v[i].first >> v[i].second;
      indegree[v[i].first]++;
      indegree[v[i].second]++;
    }
    long long int maxi = 0, idx = -1;
    for (long long int i = 1; i <= n; i++) {
      if (indegree[i] >= maxi) {
        maxi = indegree[i];
        idx = i;
      }
    }
    for (long long int i = 0; i < m; i++) {
      if (v[i].first == idx || v[i].second == idx) {
        vis[i] = 1;
        merge(v[i].first, v[i].second);
      }
    }
    for (long long int i = 0; i < m; i++) {
      if (vis[i] == 0) {
        if (getpar(v[i].first) != getpar(v[i].second)) {
          merge(v[i].first, v[i].second);
          vis[i] = 1;
        }
      }
    }
    for (long long int i = 0; i < m; i++) {
      if (vis[i] == 1) {
        cout << v[i].first << " " << v[i].second << '\n';
      }
    }
  }
  return 0;
}
