#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int T, n, m, u, v, sum, ans;
int col[N];
bool vis[N];
int cnt, head[N];
struct edge {
  int next, to;
} e[N << 1];
inline void add(int u, int v) {
  cnt++;
  e[cnt].next = head[u];
  e[cnt].to = v;
  head[u] = cnt;
}
queue<int> q;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    cnt = 0;
    for (register int i = 1; i <= n; ++i) head[i] = 0;
    for (register int i = 1; i <= m; ++i)
      scanf("%d%d", &u, &v), add(u, v), add(v, u);
    for (register int i = 1; i <= n; ++i) vis[i] = false;
    col[1] = 1;
    vis[1] = true;
    q.push(1);
    while (q.size()) {
      u = q.front();
      q.pop();
      for (register int i = head[u]; i; i = e[i].next)
        if (!vis[e[i].to]) {
          col[e[i].to] = col[u] ^ 1;
          vis[e[i].to] = true;
          q.push(e[i].to);
        }
    }
    sum = 0;
    for (register int i = 1; i <= n; ++i) sum += col[i];
    ans = min(sum, n - sum);
    printf("%d\n", ans);
    if (ans == sum) {
      for (register int i = 1; i <= n; ++i)
        if (col[i]) printf("%d ", i);
    } else {
      for (register int i = 1; i <= n; ++i)
        if (!col[i]) printf("%d ", i);
    }
    puts("");
  }
  return 0;
}
