#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 != 0) {
      ans = (ans * a) % 1000000007;
    }
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
    b >>= 1;
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    set<int> s1, s2;
    vector<int> a[n + 1];
    for (int i = 0; i < m; i++) {
      int p, q;
      cin >> p >> q;
      a[p].push_back(q);
      a[q].push_back(p);
    }
    for (int i = 1; i <= n; i++) {
      if (s2.count(i)) continue;
      s1.insert(i);
      for (auto j : a[i]) s2.insert(j);
    }
    if (s1.size() > n / 2) {
      cout << n - s1.size() << '\n';
      for (int i = 1; i <= n; i++) {
        if (s1.count(i)) continue;
        cout << i << " ";
      }
    } else {
      cout << s1.size() << '\n';
      for (auto i : s1) cout << i << " ";
    }
    cout << '\n';
  }
  return 0;
}
