#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> graph[n + 1];
    for (long long int i = 0; i < m; i++) {
      long long int u, v;
      cin >> u >> v;
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
    long long int dis[n + 1];
    memset(dis, 0, sizeof(dis));
    long long int s = 1;
    bool visited[n + 1];
    memset(visited, false, sizeof(visited));
    queue<long long int> q;
    q.push(s);
    visited[s] = true;
    dis[s] = 0;
    while (!q.empty()) {
      long long int v = q.front();
      q.pop();
      for (auto i : graph[v]) {
        if (!visited[i]) {
          visited[i] = true;
          q.push(i);
          dis[i] = dis[v] + 1;
        }
      }
    }
    vector<long long int> even, odd;
    for (long long int i = 1; i < n + 1; i++) {
      if (dis[i] % 2 == 0) {
        even.push_back(i);
      } else
        odd.push_back(i);
    }
    if (odd.size() < even.size()) {
      cout << odd.size() << endl;
      for (auto i : odd) cout << i << " ";
    } else {
      cout << even.size() << endl;
      for (auto i : even) cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}
