#include <bits/stdc++.h>
using namespace std;
int t, n, m, a, b, s;
bool vis[200200];
vector<int> vec, v[200200];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &a, &b);
      v[a].push_back(b);
      v[b].push_back(a);
    }
    queue<pair<int, int>> q;
    q.push(make_pair(1, 1));
    vis[1] = 1;
    while (!q.empty()) {
      int cur = q.front().first;
      bool st = q.front().second;
      if (st) vec.push_back(cur);
      q.pop();
      for (int j = 0; j < v[cur].size(); j++) {
        if (!vis[v[cur][j]]) {
          vis[v[cur][j]] = 1;
          q.push(make_pair(v[cur][j], !st));
        }
      }
    }
    if (vec.size() <= n / 2) {
      printf("%d\n", vec.size());
      for (int i = 0; i < vec.size(); i++) printf("%d ", vec[i]);
      printf("\n");
    } else {
      printf("%d\n", n - vec.size());
      sort(vec.begin(), vec.end());
      int j = 0;
      for (int i = 1; i <= n; i++) {
        if (j >= vec.size() || (j < vec.size() && i != vec[j]))
          printf("%d ", i);
        else
          j++;
      }
      printf("\n");
    }
    for (int i = 0; i <= n; i++) {
      vis[i] = 0;
      v[i].clear();
    }
    vec.clear();
  }
  return 0;
}
