#include <bits/stdc++.h>
using namespace std;
bool visit[200005];
long long d[200005], n, k;
vector<long long> graph[200005];
void BFS(long long s) {
  queue<long long> q;
  q.push(s);
  d[s] = 0;
  visit[s] = 1;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = 0; i < graph[u].size(); i++) {
      long long r = graph[u][i];
      if (visit[r] == 0) {
        visit[r] = 1;
        d[r] = d[u] + 1;
        q.push(r);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long ca;
  cin >> ca;
  while (ca--) {
    long long i, j;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
      long long x, y;
      cin >> x >> y;
      graph[x].push_back(y);
      graph[y].push_back(x);
    }
    BFS(1);
    vector<long long> v1, v2;
    for (i = 1; i <= n; i++) {
      if (d[i] & 1)
        v1.push_back(i);
      else
        v2.push_back(i);
    }
    if (v1.size() < v2.size()) {
      cout << v1.size() << endl;
      for (i = 0; i < v1.size(); i++) {
        cout << v1[i] << " ";
      }
      cout << endl;
    } else {
      cout << v2.size() << endl;
      for (i = 0; i < v2.size(); i++) {
        cout << v2[i] << " ";
      }
      cout << endl;
    }
    for (i = 0; i <= n + 1; i++) {
      visit[i] = 0;
      graph[i].clear();
      d[i] = 0;
    }
  }
  return 0;
}
