#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1e9 + 7;
int n, m;
vector<int> depth;
vector<bool> visited;
vector<vector<int>> adj;
void dfs(int curr, int dt) {
  depth[curr] = (dt) % 2;
  visited[curr] = true;
  for (int i = 0; i < adj[curr].size(); i++) {
    if (!visited[adj[curr][i]]) {
      dfs(adj[curr][i], dt + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    adj = vector<vector<int>>(n + 1);
    depth = vector<int>(n + 1);
    visited = vector<bool>(n + 1, false);
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(1, 0);
    vector<int> v1;
    vector<int> v2;
    for (int i = 1; i <= n; i++) {
      if (depth[i] % 2) {
        v1.push_back(i);
      } else {
        v2.push_back(i);
      }
    }
    if (v1.size() < v2.size()) {
      cout << v1.size() << endl;
      for (int i = 0; i < v1.size(); i++) {
        cout << v1[i] << " ";
      }
    } else {
      cout << v2.size() << endl;
      for (int i = 0; i < v2.size(); i++) {
        cout << v2[i] << " ";
      }
    }
    cout << endl;
  }
}
