#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
vector<int> g[M], ans[2];
int vis[M];
void dfs(int u, int s) {
  vis[u] = 1;
  ans[s].push_back(u);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (vis[v]) continue;
    dfs(v, 1 - s);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) g[i].clear(), vis[i] = 0;
    ans[0].clear(), ans[1].clear();
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0);
    int flag = ans[0].size() > ans[1].size();
    printf("%d\n", ans[flag].size());
    for (int i = 0; i < ans[flag].size(); i++) printf("%d ", ans[flag][i]);
    puts("");
  }
  return 0;
}
