#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
long long MAX = 1e9;
long long MOD = 1e9 + 7;
long long Mod = 1e9 + 7;
double EPS = 0.0001;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0};
int main() {
  int t, n, m, x, y;
  scanf("%d", &t);
  for (long long i = 0; i < t; i++) {
    scanf("%d", &n);
    scanf("%d", &m);
    vector<vector<int>> conn(n + 1);
    for (long long j = 0; j < m; j++) {
      scanf("%d", &x);
      scanf("%d", &y);
      conn[x].push_back(y);
      conn[y].push_back(x);
    }
    int d = 0;
    vector<bool> vis(n + 1, false);
    queue<pair<int, int>> q;
    vector<int> evn;
    vector<int> odd;
    pair<int, int> pr;
    q.push(make_pair(1, 0));
    while (!q.empty()) {
      pr = q.front();
      if (pr.second % 2 == 0)
        evn.push_back(pr.first);
      else
        odd.push_back(pr.first);
      q.pop();
      vis[pr.first] = true;
      for (auto it : conn[pr.first]) {
        if (!vis[it]) q.push(make_pair(it, pr.second + 1));
        vis[it] = true;
      }
    }
    if (evn.size() < odd.size()) {
      cout << evn.size() << endl;
      for (long long j = 0; j < evn.size(); j++) {
        cout << evn[j] << " ";
      }
    } else {
      cout << odd.size() << endl;
      for (long long j = 0; j < odd.size(); j++) {
        cout << odd[j] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
