#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> nei[N];
vector<pair<long long, long long> > ans;
int n, m, mxd, mx, d[N];
bool mark[N];
void dfs(int v, int dad) {
  mark[v] = true;
  for (int u : nei[v]) {
    if (!mark[u]) {
      ans.push_back({u, v});
      dfs(u, v);
    }
  }
}
int main() {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    nei[u].push_back(v);
    nei[v].push_back(u);
    d[u]++;
    d[v]++;
    if (mxd < d[u]) {
      mxd = d[u];
      mx = u;
    }
    if (mxd < d[v]) {
      mxd = d[v];
      mx = v;
    }
  }
  for (int i = 0; i < nei[mx].size(); i++) {
    ans.push_back({mx, nei[mx][i]});
    mark[nei[mx][i]] = true;
  }
  mark[mx] = true;
  for (int i = 0; i < nei[mx].size(); i++) dfs(nei[mx][i], mx);
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
}
