#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> adj[], int n, int src) {
  vector<bool> vis(n + 5, false);
  vector<int> v0, v1;
  stack<pair<int, int>> s;
  s.push({src, 0});
  int color;
  while (!s.empty()) {
    pair<int, int> temp = s.top();
    s.pop();
    src = temp.first;
    color = temp.second;
    if (vis[src] == false) {
      if (color == 0)
        v0.push_back(src);
      else
        v1.push_back(src);
      vis[src] = true;
      for (auto it : adj[src]) {
        if (!vis[it]) {
          s.push({it, color ^ 1});
        }
      }
    }
  }
  if (v0.size() < v1.size()) {
    cout << v0.size() << endl;
    for (auto it : v0) cout << it << " ";
    cout << endl;
  } else {
    cout << v1.size() << endl;
    for (auto it : v1) cout << it << " ";
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> adj[n + 5];
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(adj, n, 1);
  }
  return 0;
}
