#include <bits/stdc++.h>
template <class T>
using pt = std::pair<T, T>;
using namespace std;
struct hoba {
  vector<int> ed;
  bool mark = false, used = false;
};
vector<hoba> a;
void bfs(int st) {
  queue<int> q;
  q.push(st);
  a[st].mark = true;
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    a[z].used = true;
    for (int i = 0; i < a[z].ed.size(); i++) {
      int ind = a[z].ed[i];
      if (!a[ind].used) {
        a[ind].mark = !a[z].mark;
        q.push(ind);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  a.reserve(2e5);
  while (q--) {
    a.clear();
    int n, m;
    cin >> n >> m;
    a.resize(n + 1);
    int i1, i2;
    for (int i = 0; i < m; i++) {
      cin >> i1 >> i2;
      a[i1].ed.push_back(i2);
      a[i2].ed.push_back(i1);
    }
    bfs(1);
    int cnt = 0;
    for (int i = 1; i < a.size(); i++) {
      if (a[i].mark) cnt++;
    }
    bool ans;
    if (cnt > n / 2) {
      cout << n - cnt << '\n';
      ans = false;
    } else {
      cout << cnt << '\n';
      ans = true;
    }
    for (int i = 1; i < a.size(); i++) {
      if (a[i].mark == ans) cout << i << ' ';
    }
    cout << '\n';
  }
  return 0;
}
