#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
vector<int> adj[200009], ans[2];
bool vist[200009];
inline void dfs(int s, int id) {
  if (vist[s]) return;
  vist[s] = 1;
  ans[id].push_back(s);
  for (auto i : adj[s])
    if (vist[i] == 0) dfs(i, id ^ 1);
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      adj[i].clear();
      vist[i] = 0;
    }
    ans[0].clear();
    ans[1].clear();
    for (int i = 0; i < m; ++i) {
      int v, u;
      cin >> v >> u;
      adj[v].push_back(u);
      adj[u].push_back(v);
    }
    bool a;
    dfs(1, 0);
    if (ans[0].size() > ans[1].size())
      a = 1;
    else
      a = 0;
    cout << ans[a].size() << endl;
    for (auto i : ans[a]) cout << i << " ";
    cout << endl;
  }
  return 0;
}
