#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, m, i, j, x, y, t, u, c;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> v[n + 1], vv[3];
    pair<int, int> temp;
    int vis[n + 1];
    memset(vis, 0, sizeof vis);
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    queue<pair<int, int> > q;
    q.push({1, 0});
    vv[0].push_back(1);
    vis[1] = 1;
    while (!q.empty()) {
      temp = q.front();
      q.pop();
      u = temp.first;
      c = temp.second;
      for (i = 0; i < v[u].size(); i++) {
        if (!vis[v[u][i]]) {
          vis[v[u][i]] = 1;
          vv[!c].push_back(v[u][i]);
          q.push({v[u][i], !c});
        }
      }
    }
    int mini = vv[0].size() > vv[1].size() ? 1 : 0;
    cout << vv[mini].size() << "\n";
    for (i = 0; i < vv[mini].size(); i++) {
      cout << vv[mini][i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
