#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, M = 2e5 + 10, inf = 1e18 + 43;
vector<int> adj[M];
bool vis[M], g[M];
int s[2];
void dfs(int r, int t) {
  vis[r] = 1;
  s[t]++;
  g[r] = t;
  for (int c : adj[r]) {
    if (!vis[c]) dfs(c, !t);
  }
}
void Slove() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    vis[i] = 0;
    adj[i].clear();
  }
  s[1] = s[0] = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) dfs(i, 0);
  }
  int k = 0;
  if (s[0] > s[1]) k = 1;
  cout << s[k] << '\n';
  for (int i = 0; i < n; i++)
    if (g[i] == k) cout << i + 1 << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) Slove();
  return 0;
}
