#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int t, n, m, k, p, l, r, u, v;
int ans, cnt, flag, temp, sum;
int vis[N], c[N];
vector<int> G[N];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      G[i].clear(), vis[i] = 0, c[i] = 0;
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    sum = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        c[i] = 1;
        ++sum;
        vis[i] = 1;
        for (int j = 0, k = G[i].size(); j < k; j++) {
          vis[G[i][j]] = 1;
        }
      }
    }
    ans = sum <= n / 2;
    cout << (sum <= n / 2 ? sum : n - sum) << endl;
    for (int i = 1; i <= n; i++) {
      if (ans == c[i]) printf("%d ", i);
    }
    cout << endl;
  }
  return 0;
}
