#include <bits/stdc++.h>
using namespace std;
vector<int> v2(2000005);
vector<int> v3;
vector<int> v4;
int main() {
  ios_base::sync_with_stdio(false);
  int testcase, i;
  cin >> testcase;
  for (i = 1; i <= testcase; i++) {
    int n, m, j, k, l;
    cin >> n >> m;
    vector<int> v1[n + 1];
    vector<int> vis(n + 1, 0);
    v2.assign(n + 1, 0);
    for (j = 1; j <= m; j++) {
      cin >> k >> l;
      v1[k].push_back(l);
      v1[l].push_back(k);
    }
    queue<int> q;
    q.push(1);
    vis[1] = 1;
    v3.push_back(1);
    v2[1] = 1;
    while (!q.empty()) {
      k = q.front();
      q.pop();
      int bash = v1[k].size();
      for (j = 0; j < bash; j++) {
        if (vis[v1[k][j]] == 0) {
          q.push(v1[k][j]);
          vis[v1[k][j]] = 1;
          if (v2[k] == 0) {
            v2[v1[k][j]] = 1;
            v3.push_back(v1[k][j]);
          } else
            v4.push_back(v1[k][j]);
        }
      }
    }
    int pr = v3.size(), ti = v4.size();
    if (pr < ti) {
      cout << pr << endl;
      for (j = 0; j < pr; j++) cout << v3[j] << " ";
    } else {
      cout << ti << endl;
      for (j = 0; j < ti; j++) cout << v4[j] << " ";
    }
    cout << endl;
    v3.clear();
    v4.clear();
    v2.clear();
  }
  return 0;
}
