#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int type0, type1;
void dfs(int s, bool visited[], vector<int> adj[], int type[], int ctr) {
  if (visited[s]) return;
  visited[s] = true;
  type[s] = ctr;
  if (ctr == 0)
    type0++;
  else
    type1++;
  ctr = (ctr + 1) % 2;
  for (auto u : adj[s]) dfs(u, visited, adj, type, ctr);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    bool visited[n + 1];
    memset(visited, false, sizeof(visited));
    vector<int> adj[n + 1];
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    int type[n + 1];
    memset(type, -1, sizeof(type));
    type0 = 0;
    type1 = 0;
    int ctr = 0;
    for (int i = 1; i <= n; i++) {
      if (!visited[i]) {
        dfs(i, visited, adj, type, ctr);
      }
    }
    if (type0 <= type1) {
      cout << type0 << "\n";
      for (int i = 1; i <= n; i++) {
        if (type[i] == 0) cout << i << " ";
      }
    } else {
      cout << type1 << "\n";
      for (int i = 1; i <= n; i++) {
        if (type[i] == 1) cout << i << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
