#include <bits/stdc++.h>
using namespace std;
void bfs(long int start, long int nodes, long int dist[],
         vector<long int> adj[]) {
  queue<long int> q;
  vector<bool> vis(nodes + 1, false);
  q.push(start);
  dist[start] = 0;
  vis[start] = true;
  while (!q.empty()) {
    long int p = q.front();
    q.pop();
    for (long int i = 0; i < adj[p].size(); i++) {
      if (vis[adj[p][i]] == false) {
        dist[adj[p][i]] = dist[p] + 1;
        q.push(adj[p][i]);
        vis[adj[p][i]] = true;
      }
    }
  }
}
int main() {
  long int t;
  cin >> t;
  while (t--) {
    long int nodes, edges;
    cin >> nodes >> edges;
    vector<long int> adj[nodes + 1];
    for (long int i = 0; i < edges; i++) {
      long int x, y;
      cin >> x >> y;
      adj[x].emplace_back(y);
      adj[y].emplace_back(x);
    }
    long int dist[nodes + 1];
    memset(dist, 0, sizeof(dist));
    bfs(1, nodes, dist, adj);
    vector<long int> oddDist, evenDist;
    for (long int i = 1; i < nodes + 1; i++) {
      if (dist[i] & 1)
        oddDist.push_back(i);
      else
        evenDist.push_back(i);
    }
    if (evenDist.size() < oddDist.size()) {
      cout << evenDist.size() << "\n";
      for (auto i : evenDist) cout << i << " ";
      cout << "\n";
    } else {
      cout << oddDist.size() << "\n";
      for (auto i : oddDist) cout << i << " ";
      cout << "\n";
    }
  }
}
