#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
vector<int> vec[N];
vector<int> d[2];
bool mark[N];
void dfs(int v, int hh) {
  mark[v] = true;
  d[hh].push_back(v);
  for (int u : vec[v])
    if (!mark[u]) dfs(u, 1 - hh);
}
int main() {
  int o;
  cin >> o;
  while (o--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) vec[i].clear(), mark[i] = false;
    ;
    d[0].clear();
    d[1].clear();
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      vec[a].push_back(b);
      vec[b].push_back(a);
    }
    dfs(0, 0);
    if ((int)d[0].size() > (int)d[1].size()) swap(d[0], d[1]);
    cout << (int)d[0].size() << endl;
    for (int a : d[0]) cout << a + 1 << " ";
    cout << endl;
  }
  return 0;
}
