#include <bits/stdc++.h>
using namespace std;
long long d1[4] = {1, -1, 0, 0};
long long d2[4] = {0, 0, 1, -1};
void dfs(long long cur, vector<vector<long long>> &G, vector<long long> &seen,
         long long cnt) {
  if (cnt % 2) {
    seen[cur] = 1;
  } else {
    seen[cur] = 0;
  }
  for (auto g : G[cur]) {
    if (seen[g] != -1) continue;
    dfs(g, G, seen, cnt + 1);
  }
}
int main() {
  long long t;
  cin >> t;
  for (long long tes = (0); tes < (long long)(t); tes++) {
    long long n, m;
    cin >> n >> m;
    vector<vector<long long>> G(n);
    for (long long i = (0); i < (long long)(m); i++) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    vector<long long> ans(n, -1);
    dfs(0, G, ans, 0);
    long long cnt = 0;
    for (long long i = (0); i < (long long)(n); i++)
      if (ans[i] == 1) cnt++;
    if (cnt <= n / 2) {
      cout << cnt << endl;
      for (long long i = (0); i < (long long)(n); i++)
        if (ans[i] == 1) cout << i + 1 << " ";
    } else {
      cout << n - cnt << endl;
      for (long long i = (0); i < (long long)(n); i++)
        if (ans[i] == 0) cout << i + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
