#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[200005], u, v;
map<int, int> vis;
void dfs(int x, int c) {
  vis[x]++;
  c == 0 ? u.emplace_back(x) : v.emplace_back(x);
  for (int i = 0; i < G[x].size(); i++) {
    if (!vis.count(G[x][i])) dfs(G[x][i], !c);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      G[i].clear();
    }
    int x, y;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      G[x].emplace_back(y);
      G[y].emplace_back(x);
    }
    vis.clear();
    u.clear();
    v.clear();
    dfs(1, 0);
    if (u.size() <= v.size()) {
      cout << u.size() << endl;
      for (int i = 0; i < u.size(); i++) {
        if (i < u.size() - 1)
          cout << u[i] << " ";
        else
          cout << u[i] << endl;
      }
    } else {
      cout << v.size() << endl;
      for (int i = 0; i < v.size(); i++) {
        if (i < v.size() - 1)
          cout << v[i] << " ";
        else
          cout << v[i] << endl;
      }
    }
  }
  return 0;
}
