#include <bits/stdc++.h>
using namespace std;
const long long N = 200001;
int n, m;
vector<vector<long long> > g;
vector<long long> d, even, odd;
void COUT(vector<long long> v) {
  for (auto it : v) cout << it << ' ';
  cout << '\n';
}
void bfs(int x) {
  d = vector<long long>(n, -1);
  d[x] = 0;
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto to : g[v]) {
      if (d[to] == -1) {
        d[to] = d[v] + 1;
        q.push(to);
      }
    }
  }
  even.clear();
  odd.clear();
  for (int i = 0; i < n; i++)
    if (d[i] & 1)
      odd.push_back(i + 1);
    else
      even.push_back(i + 1);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int u, v, i;
    cin >> n >> m;
    g = vector<vector<long long> >(n);
    for (i = 0; i < m; i++) {
      cin >> u >> v;
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    bfs(0);
    if (odd.size() < even.size())
      cout << odd.size() << '\n', COUT(odd);
    else
      cout << even.size() << '\n', COUT(even);
  }
}
