#include <bits/stdc++.h>
using namespace std;
void in() { return; }
template <typename T, typename... Types>
void in(T &a, Types &...b) {
  cin >> (a);
  in(b...);
}
void o() { return; }
template <typename T, typename... Types>
void o(T a, Types... b) {
  cout << (a);
  cout << ' ';
  o(b...);
}
bool sortin(const pair<long long int, long long int> &e,
            const pair<long long int, long long int> &f) {
  return (e.first < f.first);
}
bool POT(long long int x) { return x && (!(x & (x - 1))); }
long long int i, j, k, l, m, n, p, q, r, a, b, c, x, y, z, ts, mn = 1e18,
                                                               mod = 1e9 + 7;
long long int ar[250005], br[250005], xr[250005], tem[250005];
vector<long long int> v[250005];
void dfs(long long int nod, long long int take) {
  xr[nod] = 1;
  if (take) ar[k++] = nod;
  for (long long int i = 0; i < v[nod].size(); i++) {
    long long int cur = v[nod][i];
    if (xr[cur] == 0) dfs(cur, !take);
  }
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  };
  in(ts);
  while (ts--) {
    in(n, m);
    for (long long int i = 1; i <= n; i++) v[i].clear(), xr[i] = 0;
    while (m--) {
      in(a, b);
      v[a].push_back(b);
      v[b].push_back(a);
    }
    k = 0;
    dfs(1, 1);
    if (k > n / 2) {
      k = 0;
      for (long long int i = 1; i <= n; i++) xr[i] = 0;
      dfs(1, 0);
    }
    o(k);
    cout << endl;
    for (long long int i = 0; i <= k - 1; i++) o(ar[i]);
    cout << endl;
  }
}
