#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int color[N], vis[N], ans;
int n, m;
vector<int> path[N];
void dfs(int x, int Color) {
  if (vis[x]) return;
  vis[x] = 1;
  color[x] = (Color + 1) & 1;
  ans += color[x];
  for (vector<int>::iterator i = path[x].begin(); i != path[x].end(); ++i)
    if (!vis[*i]) dfs(*i, color[x]);
}
void Init() {
  ans = 0;
  for (int i = 0; i <= n; ++i) {
    vis[i] = color[i] = 0;
    path[i].clear();
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    Init();
    while (m--) {
      int u, v;
      scanf("%d %d", &u, &v);
      path[u].push_back(v);
      path[v].push_back(u);
    }
    dfs(1, 1);
    int flag = 1;
    if (ans > n / 2) {
      flag = 0;
      ans = n - ans;
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i) {
      if (color[i] == flag) {
        ans--;
        printf("%d%c", i, " \n"[ans == 0]);
      }
    }
  }
  return 0;
}
