#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
int D[MAXN], n, m;
vector<int> adj[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int test;
  cin >> test;
  while (test--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) D[i] = INT_MAX, adj[i].clear();
    D[1] = 0;
    while (m--) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    queue<int> Q;
    Q.push(1);
    vector<int> V[2] = {{}, {}};
    while (Q.size()) {
      int u = Q.front();
      Q.pop();
      V[D[u] & 1].push_back(u);
      for (int v : adj[u])
        if (D[v] > D[u] + 1) {
          D[v] = D[u] + 1;
          Q.push(v);
        }
    }
    cout << min(V[0].size(), V[1].size()) << '\n';
    if (V[0].size() > V[1].size()) V[0].swap(V[1]);
    for (int x : V[0]) cout << x << ' ';
    cout << '\n';
  }
  return 0;
}
