#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 7;
int t;
int n, m;
vector<int> adj[MAX];
void dfs(int p, int u);
bool color[MAX], mark[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      color[i] = false;
      mark[i] = false;
      adj[i].clear();
    }
    for (int i = 1; i <= m; ++i) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(1, 1);
    int count = 0;
    vector<int> res;
    for (int i = 1; i <= n; ++i) {
      if (color[i]) {
        ++count;
        res.push_back(i);
      }
    }
    cout << count << "\n";
    for (int v : res) {
      cout << v << " ";
    }
    cout << "\n";
  }
  return 0;
}
void dfs(int p, int u) {
  mark[u] = true;
  for (int v : adj[u]) {
    if (!mark[v]) {
      dfs(u, v);
    }
  }
  if (!color[u]) {
    bool ok = false;
    for (int v : adj[u]) {
      if (color[v]) {
        ok = true;
        break;
      }
    }
    if (!ok) {
      color[p] = true;
    }
  }
}
