#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > v(2000000);
void bfs(long long n, long long m) {
  map<long long, long long> level, fr;
  vector<long long> o, e;
  fr[n] = 1;
  level[n] = 0;
  e.push_back(n);
  queue<long long> q;
  q.push(n);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = 0; i < v[x].size(); i++) {
      if (fr[v[x][i]] == 0) {
        fr[v[x][i]] = 1;
        level[v[x][i]] = level[x] + 1;
        if (level[v[x][i]] % 2 == 1)
          o.push_back(v[x][i]);
        else
          e.push_back(v[x][i]);
        q.push(v[x][i]);
      }
    }
  }
  if (e.size() <= m / 2) {
    cout << e.size() << endl;
    for (long long i = 0; i < e.size(); i++) cout << e[i] << " ";
  } else {
    cout << o.size() << endl;
    for (long long i = 0; i < o.size(); i++) cout << o[i] << " ";
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k, i, j, h;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    v.clear();
    v.resize(n + 1);
    for (i = 0; i < m; i++) {
      long long x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    bfs(1, n);
  }
}
