#include <bits/stdc++.h>
using namespace std;
std::vector<long long int> a[200005];
long long int vis[200005], b[200005];
void dfs(long long int node) {
  vis[node] = 1;
  for (auto i : a[node])
    if (!vis[i]) {
      b[i] = 1 - b[node];
      dfs(i);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long int n, m;
    cin >> n >> m;
    for (int i = 1; i < n + 3; i++) {
      a[i].clear();
      vis[i] = 0;
      b[i] = 0;
    }
    for (int i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      a[x].push_back(y);
      a[y].push_back(x);
    }
    b[1] = 1;
    dfs(1);
    long long int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (b[i]) cnt++;
    }
    if (cnt > n / 2) {
      cout << n - cnt << '\n';
      for (int i = 1; i <= n; i++) {
        if (!b[i]) cout << i << " ";
      }
    } else {
      cout << cnt << '\n';
      for (int i = 1; i <= n; i++) {
        if (b[i]) cout << i << " ";
      }
    }
    cout << '\n';
  }
  return 0;
}
