#include <bits/stdc++.h>
using namespace std;
long long hell = 200005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> level(n + 5);
    vector<int> lev[n + 5];
    vector<int> vis(n + 5, 0);
    vector<int> adj[n + 5];
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    queue<int> q;
    q.push(1);
    vis[1] = true;
    level[1] = 0;
    lev[0].push_back(1);
    while (!q.empty()) {
      int head = q.front();
      q.pop();
      for (auto x : adj[head]) {
        if (vis[x] == false) {
          vis[x] = true;
          level[x] = level[head] + 1;
          lev[level[x]].push_back(x);
          q.push(x);
        }
      }
    }
    int even = 0, odd = 0;
    vector<int> ev;
    vector<int> od;
    for (int i = 0; i <= n; i++) {
      if (i % 2 == 0) {
        even += lev[i].size();
        for (auto x : lev[i]) ev.push_back(x);
      } else {
        odd += lev[i].size();
        for (auto x : lev[i]) od.push_back(x);
      }
    }
    if (even <= n / 2) {
      cout << even << endl;
      for (auto x : ev) cout << x << " ";
    } else {
      cout << odd << endl;
      for (auto x : od) cout << x << " ";
    }
    cout << endl;
  }
  return 0;
}
