#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
long long int mini(long long int a, long long int b) { return a < b ? a : b; }
long long int maxi(long long int a, long long int b) { return a > b ? a : b; }
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int binpow(long long int n, long long int x) {
  long long int ans = 1;
  while (x) {
    if (x & 1) ans *= n;
    n *= n;
    x >>= 1;
  }
  return ans;
}
vector<int> edge[int(2e5 + 10)];
vector<bool> vis;
vector<int> ev, od;
void dfs(int x, bool par) {
  vis[x] = true;
  if (par)
    ev.push_back(x);
  else
    od.push_back(x);
  for (auto nod : edge[x]) {
    if (!vis[nod]) {
      dfs(nod, !par);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= n; ++i) {
      edge[i].erase(edge[i].begin(), edge[i].end());
    }
    vis.erase(vis.begin(), vis.end());
    vis.resize(n + 1, false);
    ev.erase(ev.begin(), ev.end());
    od.erase(od.begin(), od.end());
    int u, v;
    for (int i = 0; i < m; ++i) {
      cin >> u >> v;
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    dfs(1, true);
    if (ev.size() < od.size()) {
      cout << ev.size() << "\n";
      for (auto i : ev) cout << i << " ";
      cout << "\n";
    } else {
      cout << od.size() << "\n";
      for (auto i : od) cout << i << " ";
      cout << "\n";
    }
  }
  return 0;
}
