#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int testcases;
  cin >> testcases;
  for (int dh = 0; dh < testcases; ++dh) {
    int n, m;
    cin >> n >> m;
    vector<int> v[n];
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    vector<int> distance(n, INT_MIN);
    vector<int> odd, even;
    distance[0] = 0;
    queue<int> q;
    even.push_back(0);
    q.push(0);
    while (!q.empty()) {
      int w = q.front();
      q.pop();
      for (int j = 0; j < v[w].size(); ++j) {
        if (distance[v[w][j]] == INT_MIN) {
          q.push(v[w][j]);
          distance[v[w][j]] = distance[w] + 1;
          if (distance[v[w][j]] % 2 == 0)
            even.push_back(v[w][j]);
          else
            odd.push_back(v[w][j]);
        }
      }
    }
    if (odd.size() < even.size()) {
      cout << odd.size() << endl;
      for (auto it : odd) {
        cout << it + 1 << " ";
      }
      cout << endl;
    } else {
      cout << even.size() << endl;
      for (auto it : even) {
        cout << it + 1 << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
