#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200500;
int n, m;
vector<int> g[MAXN];
int col[MAXN];
void bfs(int src) {
  queue<int> Q;
  Q.push(src);
  col[src] = 0;
  while (((int)Q.size())) {
    int p = Q.front();
    Q.pop();
    for (int q : g[p])
      if (col[q] == -1) {
        col[q] = 1 - col[p];
        Q.push(q);
      }
  }
}
vector<int> Ans;
void get_black() {
  for (int i = (0); i < (int)(n); i++)
    if (col[i]) Ans.push_back(i + 1);
}
void get_white() {
  for (int i = (0); i < (int)(n); i++)
    if (!col[i]) Ans.push_back(i + 1);
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = (0); i < (int)(MAXN); i++) col[i] = -1;
  for (int cs = (0); cs < (int)(t); cs++) {
    scanf("%d %d", &n, &m);
    for (int i = (0); i < (int)(m); i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      u--;
      v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    bfs(0);
    int bk = 0, wt = 0;
    for (int i = (0); i < (int)(n); i++) {
      assert(col[i] > -1);
      if (col[i])
        bk++;
      else
        wt++;
    }
    Ans.clear();
    if (bk <= wt)
      get_black();
    else
      get_white();
    printf("%d\n", ((int)Ans.size()));
    for (int i = (0); i < (int)(((int)Ans.size())); i++) {
      if (i) printf(" ");
      printf("%d", Ans[i]);
    }
    puts("");
    for (int i = (0); i < (int)(n); i++) g[i].clear();
    for (int i = (0); i < (int)(n); i++) col[i] = -1;
  }
  return 0;
}
