#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> e;
vector<int> o;
vector<bool> visited;
void bfs() {
  queue<int> q;
  q.push(1);
  bool flag = true;
  while (!q.empty()) {
    flag = !flag;
    int si = q.size();
    while (si--) {
      int u = q.front();
      q.pop();
      if (flag)
        e.push_back(u);
      else
        o.push_back(u);
      visited[u] = true;
      for (auto it : g[u]) {
        if (visited[it] == false) {
          visited[it] = true;
          q.push(it);
        }
      }
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    o.clear();
    e.clear();
    int n, m;
    cin >> n >> m;
    visited.clear();
    g = vector<vector<int>>(n + 1);
    for (int i = 0; i <= n; i++) visited.push_back(false);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    bfs();
    if (o.size() < e.size()) {
      cout << o.size() << "\n";
      for (int i = 0; i < o.size(); i++) cout << o[i] << " ";
      cout << "\n";
    } else {
      cout << e.size() << "\n";
      for (int i = 0; i < e.size(); i++) cout << e[i] << " ";
      cout << "\n";
    }
  }
}
