#include <bits/stdc++.h>
long long max(long long A, long long b) {
  if (A > b) return A;
  return b;
}
long long min(long long A, long long b) {
  if (A < b) return A;
  return b;
}
using namespace std;
vector<long long> graph[200005];
vector<long long> x, y;
long long visited[200005];
void dfs(long long current, long long c) {
  visited[current] = 1;
  if (c == 1)
    x.push_back(current);
  else
    y.push_back(current);
  for (int i = 0; i < graph[current].size(); i++) {
    if (!visited[graph[current][i]]) dfs(graph[current][i], c ^ 1);
  }
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long a, b;
    for (int i = 0; i < m; i++) {
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }
    dfs(1, 1);
    if (x.size() <= y.size()) {
      cout << x.size() << endl;
      for (int i = 0; i < x.size(); i++) cout << x[i] << " ";
      cout << endl;
    } else {
      cout << y.size() << endl;
      for (int i = 0; i < y.size(); i++) cout << y[i] << " ";
      cout << endl;
    }
    for (int i = 1; i <= n; i++) {
      graph[i].clear();
      visited[i] = 0;
    }
    x.clear();
    y.clear();
  }
}
