#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> vs[maxn];
int vis[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      vs[x].push_back(y);
      vs[y].push_back(x);
    }
    vector<int> vc;
    queue<int> qu;
    qu.push(1);
    vis[1] = 1;
    while (!qu.empty()) {
      int x = qu.front();
      qu.pop();
      if (vis[x] % 2 == 1) vc.push_back(x);
      for (int i = 0; i < vs[x].size(); i++) {
        int u = vs[x][i];
        if (vis[u])
          continue;
        else {
          qu.push(u);
          vis[u] = vis[x] + 1;
        }
      }
    }
    for (int i = 1; i <= n; i++) vis[i] = 0;
    vector<int> vq;
    qu.push(1);
    vis[1] = 1;
    while (!qu.empty()) {
      int x = qu.front();
      qu.pop();
      if (vis[x] % 2 == 0) vq.push_back(x);
      for (int i = 0; i < vs[x].size(); i++) {
        int u = vs[x][i];
        if (vis[u])
          continue;
        else {
          qu.push(u);
          vis[u] = vis[x] + 1;
        }
      }
    }
    if (vc.size() <= n / 2) {
      cout << vc.size() << endl;
      for (int i = 0; i < vc.size(); i++) cout << vc[i] << " ";
      cout << endl;
    } else {
      cout << vq.size() << endl;
      for (int i = 0; i < vq.size(); i++) cout << vq[i] << " ";
      cout << endl;
    }
    for (int i = 1; i <= n; i++) {
      vis[i] = 0;
      vs[i].clear();
    }
  }
}
