#include <bits/stdc++.h>
using namespace std;
void find() {
  int no_of_vertex, no_of_edge;
  cin >> no_of_vertex >> no_of_edge;
  vector<vector<int> > adj(no_of_vertex + 2);
  int input1, input2;
  for (int i = 0; i < no_of_edge; i++) {
    cin >> input1 >> input2;
    adj[input1].push_back(input2);
    adj[input2].push_back(input1);
  }
  deque<pair<int, int> > q1;
  vector<int> visited(no_of_vertex + 2, -1);
  q1.push_back({1, 1});
  visited[1] = 1;
  while (q1.size() != 0) {
    pair<int, int> a = q1.front();
    q1.pop_front();
    for (auto k : adj[a.second]) {
      if (visited[k] == -1) {
        visited[k] = (a.first + 1) % 2;
        q1.push_back({(a.first + 1) % 2, k});
      }
    }
  }
  int count1 = 0;
  for (int i = 1; i <= no_of_vertex; i++) {
    if (visited[i] == 1) {
      count1++;
    }
  }
  vector<int> ans;
  if (count1 <= no_of_vertex - count1) {
    for (int i = 1; i <= no_of_vertex; i++) {
      if (visited[i] == 1) {
        ans.push_back(i);
      }
    }
  } else {
    for (int i = 1; i <= no_of_vertex; i++) {
      if (visited[i] == 0) {
        ans.push_back(i);
      }
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return;
}
int main() {
  int no_of_input;
  cin >> no_of_input;
  for (int i = 0; i < no_of_input; i++) {
    find();
  }
}
