#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t, n, m, u, v;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<vector<long long>> adj(n);
    for (long long i = 0; i < m; i++) {
      cin >> u >> v;
      --u, --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    vector<long long> side(n, -1), cnt(2, 0);
    queue<long long> q;
    q.push(0);
    side[0] = 0;
    cnt[0] = 1;
    while (q.size()) {
      long long u = q.front();
      q.pop();
      for (auto v : adj[u]) {
        if (side[v] != -1) continue;
        q.push(v);
        side[v] = side[u] ^ 1;
        cnt[side[v]]++;
      }
    }
    long long type = (cnt[0] < cnt[1] ? 0 : 1);
    cout << cnt[type] << "\n";
    for (long long i = 0; i < n; i++) {
      if (side[i] != type) continue;
      cout << i + 1 << " ";
    }
    cout << "\n";
  }
  return 0;
}
