#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const long double EPS = 1e-10;
const int N = 2e5 + 5;
vector<int> adj[N];
int clr[N];
void bfs(int st = 0);
int main() {
  int t;
  scanf("%d", &(t));
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      adj[i].clear();
      clr[i] = 0;
    }
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--, v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    int cnt = 0;
    bfs();
    for (int i = 0; i < n; i++) {
      if (clr[i] == 1) cnt++;
    }
    bool invert = (cnt > n / 2);
    printf("%d\n", (invert) ? n - cnt : cnt);
    for (int i = 0; i < n; i++) {
      if (!invert && clr[i] == 1)
        printf("%d ", i + 1);
      else if (invert && clr[i] == 2)
        printf("%d ", i + 1);
    }
    printf("\n");
  }
  return 0;
}
void bfs(int st) {
  clr[st] = 1;
  queue<int> q;
  q.push(st);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto& v : adj[u]) {
      if (!clr[v]) q.push(v), clr[v] = clr[u] ^ 3;
    }
  }
}
