#include <bits/stdc++.h>
using namespace std;
const int t = 200005;
vector<int> grafo[t];
void bfs(int x, vector<int>& dist) {
  queue<int> fila;
  fila.push(x);
  dist[x] = 0;
  while (!fila.empty()) {
    int vv = fila.front();
    fila.pop();
    for (int v : grafo[vv]) {
      if (dist[v] == -1) {
        dist[v] = dist[vv] + 1;
        fila.push(v);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc, n, m;
  int a, b;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    while (m--) {
      cin >> a >> b;
      grafo[a].push_back(b);
      grafo[b].push_back(a);
    }
    vector<int> dist(n + 1, -1);
    bfs(1, dist);
    vector<int> impar, par;
    for (int i = 1; i <= n; i++) {
      if (dist[i] & 1)
        impar.push_back(i);
      else
        par.push_back(i);
    }
    int ti = impar.size();
    int tp = par.size();
    if (ti < tp) {
      cout << ti << "\n";
      for (int i = 0; i < ti; i++) {
        if (i) cout << " ";
        cout << impar[i];
      }
    } else {
      cout << tp << "\n";
      for (int i = 0; i < tp; i++) {
        if (i) cout << " ";
        cout << par[i];
      }
    }
    cout << "\n";
    for (int i = 1; i <= n; i++) grafo[i].clear();
  }
  return 0;
}
