#include <bits/stdc++.h>
using namespace std;
vector<long long> gr[200011];
vector<long long> v;
vector<long long> v1;
bool vis[200011];
queue<pair<long long, bool> > q;
long long n, m;
void bfs(long long s, bool k) {
  q.push({s, k});
  while (!q.empty()) {
    long long node = q.front().first;
    bool z = q.front().second;
    q.pop();
    if (vis[node]) continue;
    if (z)
      v.push_back(node);
    else
      v1.push_back(node);
    vis[node] = 1;
    for (int i = 0; i < gr[node].size(); i++)
      if (!vis[gr[node][i]]) q.push({gr[node][i], !z});
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long q, i, x, y;
  cin >> q;
  while (q--) {
    cin >> n >> m;
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      gr[x].push_back(y);
      gr[y].push_back(x);
    }
    v.clear();
    v1.clear();
    bfs(1, 0);
    if (v.size() <= n / 2) {
      cout << v.size() << endl;
      for (i = 0; i < v.size(); i++) cout << v[i] << " ";
      cout << endl;
    } else {
      cout << v1.size() << endl;
      for (i = 0; i < v1.size(); i++) cout << v1[i] << " ";
      cout << endl;
    }
    for (i = 1; i <= n; i++) {
      vis[i] = 0;
      gr[i].clear();
    }
  }
  return 0;
}
