#include <bits/stdc++.h>
using namespace std;
int test, u, v, n, m, cnt, used[200005];
vector<int> G[200005];
void DFS(int u) {
  int v;
  for (int i = 0; i < G[u].size(); i++) {
    v = G[u][i];
    if (used[v] == 0) {
      used[v] = used[u] + 1;
      if (used[v] % 2 == 0) cnt++;
      DFS(v);
    }
  }
}
int main() {
  cin >> test;
  while (test--) {
    cin >> n >> m;
    cnt = 0;
    for (int i = 1; i <= m; i++) {
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    used[1] = 1;
    DFS(1);
    cout << min(cnt, n - cnt) << endl;
    for (int i = 1; i <= n; i++) {
      if ((cnt <= n / 2) && (used[i] % 2 == 0))
        cout << i << ' ';
      else if ((cnt > n / 2) && (used[i] % 2 == 1))
        cout << i << ' ';
      used[i] = 0;
      G[i].clear();
    }
    cout << endl;
  }
  return 0;
}
