#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> v[n + 1];
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    queue<int> q;
    q.push(1);
    bool vstd[n + 1];
    memset(vstd, false, sizeof vstd);
    vector<int> odd;
    vector<int> even;
    int col[n + 1];
    memset(col, 0, sizeof col);
    col[1] = 2;
    while (q.size()) {
      int node = q.front();
      q.pop();
      if (vstd[node]) continue;
      vstd[node] = true;
      for (auto u : v[node]) {
        if (col[u] == 0) {
          col[u] = 3 - col[node];
        }
        q.push(u);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (col[i] == 1) {
        odd.push_back(i);
      } else {
        even.push_back(i);
      }
    }
    if (odd.size() < even.size()) {
      cout << odd.size() << endl;
      for (auto u : odd) {
        cout << u << " ";
      }
      cout << endl;
    } else {
      cout << even.size() << endl;
      for (auto u : even) {
        cout << u << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
