#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, cnt = 0;
long long head[400005], depth[200005], visited[200005];
vector<long long> ve[5];
struct edge {
  long long next;
  long long to;
} e[400005];
queue<long long> q;
inline void add_edge(long long u, long long v) {
  cnt++;
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
inline void bfs() {
  q.push(1);
  depth[1] = 0;
  visited[1] = 1;
  while (!q.empty()) {
    long long now = q.front();
    for (long long i = head[now]; i; i = e[i].next) {
      if (visited[e[i].to] == 0) {
        depth[e[i].to] = depth[now] + 1;
        q.push(e[i].to);
        visited[e[i].to] = 1;
      }
    }
    visited[now] = 1;
    q.pop();
  }
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    cnt = 0;
    for (long long i = 0; i <= 1; i++) ve[i].clear();
    for (long long i = 1; i <= n; i++) visited[i] = 0;
    for (long long i = 1; i <= 2 * n; i++) head[i] = e[i].next = e[i].to = 0;
    for (long long i = 1; i <= m; i++) {
      cin >> u >> v;
      add_edge(u, v);
      add_edge(v, u);
    }
    bfs();
    for (long long i = 1; i <= n; i++) ve[depth[i] % 2].push_back(i);
    if (ve[0].size() <= ve[1].size()) {
      cout << ve[0].size() << endl;
      for (long long i = 0; i < ve[0].size(); i++) cout << ve[0][i] << ' ';
      cout << endl;
    } else {
      cout << ve[1].size() << endl;
      for (long long i = 0; i < ve[1].size(); i++) cout << ve[1][i] << ' ';
      cout << endl;
    }
  }
  return 0;
}
