#include <bits/stdc++.h>
using namespace std;
vector<int> vec1;
vector<int> vec2;
int sz, m, n;
vector<int> graph[200005];
int vis[200005];
void DFS(int start, int col) {
  if (vis[start]) return;
  vis[start] = 1;
  if (col == 1)
    vec1.push_back(start);
  else
    vec2.push_back(start);
  for (int i = 0; i < graph[start].size(); i++) {
    int u = graph[start][i];
    if (!vis[u] && col == 1) {
      DFS(u, 2);
    }
    if (!vis[u] && col == 2) {
      DFS(u, 1);
    }
  }
}
int main() {
  int q, t;
  scanf("%d", &t);
  while (t--) {
    int i, j, u, v;
    vec1.clear();
    vec2.clear();
    scanf("%d%d", &n, &m);
    for (i = 0; i <= n + 2; i++) {
      graph[i].clear();
      vis[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
    DFS(1, 1);
    if (vec1.size() <= vec2.size()) {
      printf("%d\n", vec1.size());
      for (i = 0; i < vec1.size(); i++) printf("%d ", vec1[i]);
      printf("\n");
    } else {
      printf("%d\n", vec2.size());
      for (i = 0; i < vec2.size(); i++) printf("%d ", vec2[i]);
      printf("\n");
    }
  }
  return 0;
}
