#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 5;
vector<long long> v[maxn];
void f() {
  long long n, m;
  cin >> n >> m;
  vector<bool> visited(n + 1, 0);
  vector<long long> ans[2];
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  deque<pair<long long, long long> > s;
  s.push_back({1, 0});
  while (!s.empty()) {
    long long id = s.front().first;
    long long dist = s.front().second;
    s.pop_front();
    if (visited[id]) continue;
    visited[id] = 1;
    ans[dist % 2].emplace_back(id);
    for (const auto &it : v[id]) {
      if (visited[it]) continue;
      s.push_back({it, dist + 1});
    }
  }
  long long t = 0;
  if (ans[1].size() < ans[0].size()) t = 1;
  cout << ans[t].size() << '\n';
  ;
  for (const auto &it : ans[t]) {
    cout << it << " ";
  }
  cout << '\n';
  ;
  for (long long i = 1; i <= n; ++i) v[i].clear();
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    f();
  }
  return 0;
}
