#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
vector<vector<long long int> > v(200004);
long long int deg[200004], vis[200004];
vector<pair<long long int, long long int> > ans;
void dfs(long long int node) {
  vis[node] = 1;
  long long int sz = v[node].size();
  for (int i = 0; i < sz; i++) {
    if (!vis[v[node][i]]) {
      ans.push_back(make_pair(node, v[node][i]));
      dfs(v[node][i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m, x, y;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  long long int ma = 0, node;
  for (int i = 1; i <= n; i++) {
    if (deg[i] > ma) {
      ma = deg[i];
      node = i;
    }
  }
  int sz = v[node].size(), ch;
  vis[node] = 1;
  for (int i = 0; i < sz; i++) {
    ch = v[node][i];
    ans.push_back(make_pair(ch, node));
    vis[ch] = 1;
  }
  for (int i = 0; i < sz; i++) {
    ch = v[node][i];
    dfs(ch);
  }
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
