#include <bits/stdc++.h>
using namespace std;
int n;
int m;
vector<vector<int>> neighbors;
void input() {
  cin >> n >> m;
  neighbors.clear();
  neighbors.resize(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    neighbors[x].push_back(y);
    neighbors[y].push_back(x);
  }
}
vector<bool> visited;
vector<int> color;
int Count[2];
vector<int> answer[2];
int solve() {
  answer[0].clear();
  answer[1].clear();
  Count[0] = Count[1] = 0;
  visited.clear();
  visited.resize(n, false);
  color.clear();
  color.resize(n, 0);
  queue<int> Q;
  Q.push(0);
  visited[0] = true;
  color[0] = 0;
  Count[0] = 1;
  answer[0].push_back(0);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int y : neighbors[x]) {
      if (!visited[y]) {
        color[y] = !color[x];
        ++Count[color[y]];
        visited[y] = true;
        Q.push(y);
        answer[color[y]].push_back(y);
      }
    }
  }
  return Count[0] * 2 < n ? 0 : 1;
}
void output(const vector<int>& A) {
  cout << A.size() << "\n";
  for (int i = 0; i < A.size(); ++i) {
    if (i != 0) cout << " ";
    cout << A[i] + 1;
  }
  cout << "\n";
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    input();
    output(answer[solve()]);
  }
  return 0;
}
