#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> adj;
long long int n, m;
void BFS() {
  vector<bool> level(n + 1, false), visit(n + 1, false);
  queue<long long int> Q;
  Q.push(1);
  visit[1] = true;
  while (!Q.empty()) {
    long long int P = Q.front();
    Q.pop();
    bool L = level[P];
    L = !L;
    for (int i = 0; i < adj[P].size(); i++) {
      if (!visit[adj[P][i]]) {
        level[adj[P][i]] = L;
        visit[adj[P][i]] = true;
        Q.push(adj[P][i]);
      }
    }
  }
  long long int count = 0;
  for (int i = 1; i <= n; i++) {
    if (level[i]) {
      count++;
    }
  }
  if (count <= n / 2) {
    cout << count << endl;
    for (int i = 1; i <= n; i++) {
      if (level[i]) {
        cout << i << " ";
      }
    }
  } else {
    cout << n - count << endl;
    for (int i = 1; i <= n; i++) {
      if (!level[i]) {
        cout << i << " ";
      }
    }
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    adj.assign(n + 1, vector<long long int>());
    for (int i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    BFS();
  }
}
