#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int mo = 1e9 + 7;
vector<int> p[N];
int v[N], c1, c2, cl;
void dfs(int x) {
  for (auto i : p[x])
    if (!v[i]) {
      v[i] = 3 - v[x];
      dfs(i);
    }
  if (v[x] == 1)
    ++c1;
  else
    ++c2;
}
void sol() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i) v[i] = 0, p[i].clear();
  for (int i = (1); i <= (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    p[x].push_back(y);
    p[y].push_back(x);
  }
  c1 = c2 = cl = 0;
  for (int i = (1); i <= (n); ++i)
    if (!v[i]) {
      if (p[i].empty())
        ++cl;
      else {
        v[i] = 1;
        dfs(i);
      }
    }
  if (c1 > c2) {
    printf("%d\n", c2 + cl);
    for (int i = (1); i <= (n); ++i)
      if (v[i] != 1) printf("%d ", i);
  } else {
    printf("%d\n", c1 + cl);
    for (int i = (1); i <= (n); ++i)
      if (v[i] != 2) printf("%d ", i);
  }
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = (1); i <= (t); ++i) sol();
}
