#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n, m;
vector<int> cost;
vector<vector<int>> G;
void bfs(int start) {
  queue<int> q;
  q.push(start);
  cost = vector<int>(n + 2, -1);
  cost[start] = 0;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int child : G[node]) {
      if (cost[child] == -1) {
        cost[child] = cost[node] + 1;
        q.push(child);
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  G = vector<vector<int>>(n + 3);
  for (int i = 0, x, y; i < m; i++) {
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  bfs(1);
  vector<int> odd, even;
  for (int i = 1; i <= n; i++) {
    if (cost[i] % 2)
      odd.push_back(i);
    else
      even.push_back(i);
  }
  if (odd.size() > even.size()) {
    cout << even.size() << "\n";
    for (int v : even) {
      cout << v << " ";
    }
  } else {
    cout << odd.size() << "\n";
    for (int v : odd) {
      cout << v << " ";
    }
  }
  cout << "\n";
}
int(main)() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
