#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long height[n + 1];
    for (long long i = 0; i <= n; i++) height[i] = 0;
    vector<long long> adj[n + 1];
    vector<long long> abc[2];
    for (long long i = 1; i <= m; i++) {
      long long a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    std::queue<pair<long long, long long> > Q;
    Q.push({1, 0});
    long long visited[n + 1];
    for (long long i = 0; i <= n; i++) visited[i] = 0;
    visited[1] = 1;
    while (Q.size()) {
      auto cur = Q.front();
      Q.pop();
      long long a = cur.first, b = cur.second;
      height[a] = b % 2;
      abc[b % 2].push_back(a);
      for (auto i : adj[a]) {
        if (visited[i] == 0) {
          Q.push({i, b + 1});
          visited[i] = 1;
        }
      }
    }
    if (abc[0].size() < abc[1].size()) {
      cout << abc[0].size() << "\n";
      for (auto i : abc[0]) cout << i << " ";
      cout << '\n';
    } else {
      cout << abc[1].size() << "\n";
      for (auto i : abc[1]) cout << i << " ";
      cout << '\n';
    }
  }
  return 0;
}
