#include <bits/stdc++.h>
using namespace std;
long long int vis[2000001], cp, deg[2000001] = {0};
vector<long long int> cnt, adj[2000001], cps;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, n, m, j, k, x, y, z, l, r;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  long long int mx = 0, mxi = 1;
  for (i = 1; i <= n; i++) {
    if (mx < deg[i]) {
      mx = deg[i];
      mxi = i;
    }
  }
  queue<long long int> q;
  q.push(mxi);
  vis[mxi] = 1;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (i = 0; i < adj[x].size(); i++) {
      if (!vis[adj[x][i]]) {
        q.push(adj[x][i]);
        vis[adj[x][i]] = 1;
        cout << x << " " << adj[x][i] << "\n";
      }
    }
  }
  return 0;
}
