#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
vector<int> adj[N];
int vis[N];
int n, m;
void solve() {
  cin >> n >> m;
  int mx = 0, l;
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (mx < adj[u].size()) mx = adj[u].size(), l = u;
    if (mx < adj[v].size()) mx = adj[v].size(), l = v;
  }
  queue<int> q;
  q.push(l);
  vis[l] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int y : adj[x])
      if (!vis[y]) {
        cout << x << " " << y << "\n";
        vis[y] = 1;
        q.push(y);
      }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t-- > 0) solve();
  return 0;
}
