#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans;
int degree[200000 + 1] = {0};
map<pair<int, int>, int> mp;
vector<int> v[200000 + 1];
int vis[200000 + 1] = {0};
void dfs(int x) {
  vis[x] = 1;
  for (auto it = v[x].begin(); it != v[x].end(); it++) {
    if (vis[(*it)] == 0) {
      ans.push_back({x, *it});
      dfs(*it);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    mp[{a, b}] = 1;
    mp[{b, a}] = 1;
    degree[a]++;
    degree[b]++;
  }
  int l;
  int maxi = -1;
  for (int i = 1; i <= n; i++) {
    if (degree[i] > maxi) {
      maxi = degree[i];
      l = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (mp[{i, l}] == 1) {
      ans.push_back({i, l});
      vis[i] = 1;
    }
  }
  vis[l] = 1;
  if (ans.size() != n - 1) {
    for (int i = 0; i < ans.size(); i++) {
      dfs(ans[i].first);
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
