#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<vector<long long>> adj(n + 1);
    vector<long long> vis(n + 1), lvl(n + 1);
    for (long long i = 0; i < m; i++) {
      long long x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    queue<long long> q;
    q.push(1);
    vis[1] = lvl[1] = 1;
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      for (auto node : adj[x]) {
        if (!vis[node]) {
          lvl[node] = lvl[x] + 1;
          vis[node] = 1;
          q.push(node);
        }
      }
    }
    vector<long long> odd, eve;
    for (long long i = 1; i <= n; i++) {
      if (lvl[i] % 2 == 1)
        odd.push_back(i);
      else
        eve.push_back(i);
    }
    if (odd.size() <= n / 2) {
      cout << odd.size() << "\n";
      for (auto x : odd) cout << x << " ";
    } else {
      cout << eve.size() << "\n";
      for (auto x : eve) cout << x << " ";
    }
    cout << "\n";
  }
  return 0;
}
