#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unrolled-loops")
int n, m, b, w, color[200010], ok[200010];
vector<int> a[200010];
void dfs(int u, int c) {
  color[u] = c;
  ok[u] = 1;
  b += (c == 0);
  w += (c == 1);
  for (int i = 0; i < a[u].size(); i++)
    if (!ok[a[u][i]]) dfs(a[u][i], 1 - c);
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    a[i].clear();
    color[i] = 0;
    ok[i] = 0;
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  b = 0;
  w = 0;
  dfs(1, 0);
  cout << min(b, w) << '\n';
  if (b < w)
    for (int i = 1; i <= n; i++) {
      if (!color[i]) cout << i << " ";
    }
  else
    for (int i = 1; i <= n; i++) {
      if (color[i]) cout << i << " ";
    }
  cout << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
