#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n, m;
    cin >> n >> m;
    vector<bool> vis(n, false);
    vector<int> layer(n, -1);
    vector<vector<int>> ng(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      ng[u - 1].push_back(v - 1);
      ng[v - 1].push_back(u - 1);
    }
    queue<pair<int, int>> qe;
    qe.push(make_pair(0, 0));
    pair<int, int> temp;
    while (!qe.empty()) {
      temp = qe.front();
      int a1 = temp.first, a2 = temp.second;
      qe.pop();
      if (vis[temp.first]) continue;
      layer[a1] = a2;
      for (auto x : ng[a1]) {
        if (vis[x]) continue;
        qe.push(make_pair(x, a2 + 1));
      }
      vis[a1] = true;
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (layer[i] % 2 == 0) count++;
    }
    int par;
    if (count <= n / 2)
      par = 0;
    else {
      par = 1;
      count = n - count;
    }
    printf("%d\n", count);
    for (int i = 0; i < n; i++) {
      if (layer[i] % 2 == par) {
        printf("%d ", i + 1);
      }
    }
    printf("\n");
  }
  return 0;
}
