#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int t;
int n;
int m;
int vis[N];
int dist[N];
vector<int> adj[N];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      vis[i] = dist[i] = 0;
      adj[i].clear();
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 1;
      for (auto v : adj[u]) {
        if (vis[v]) continue;
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
    vector<int> od, ev;
    for (int i = 1; i <= n; i++) {
      if (dist[i] & 1) {
        od.push_back(i);
      } else {
        ev.push_back(i);
      }
    }
    if (ev.size() < od.size()) {
      printf("%d\n", (int)ev.size());
      for (auto u : ev) {
        printf("%d ", u);
      }
      puts("");
    } else {
      printf("%d\n", (int)od.size());
      for (auto u : od) {
        printf("%d ", u);
      }
      puts("");
    }
  }
  return 0;
}
