#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > g(n + 1);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<int> res(n + 1), done(n + 1);
    queue<pair<int, int> > q;
    q.emplace(1, 1);
    done[1] = 1;
    int has = 0;
    while (!q.empty()) {
      auto [u, c] = q.front();
      q.pop();
      has += c;
      res[u] = c;
      for (int v : g[u]) {
        if (!done[v]) {
          done[v] = 1;
          q.emplace(v, !c);
        }
      }
    }
    bool ok = 0;
    if (has <= n / 2) {
      ok = 1;
    }
    cout << (ok ? has : n - has) << "\n";
    for (int i = 1; i <= n; i++) {
      if (res[i] == ok) {
        cout << i << " ";
      }
    }
    cout << "\n";
  }
}
