#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<int> adj[MAXN];
int deg[MAXN];
bool vis[MAXN];
struct Edge {
  int u, v;
  Edge(int a, int b) {
    u = a;
    v = b;
  }
};
vector<Edge> ans;
void dfs(int u) {
  vis[u] = true;
  for (int v : adj[u]) {
    if (vis[v]) {
      continue;
    }
    ans.push_back(Edge(u, v));
    dfs(v);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int mx_deg = 0, mx_node = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
    if (deg[u] > mx_deg) {
      mx_deg = deg[u];
      mx_node = u;
    }
    if (deg[v] > mx_deg) {
      mx_deg = deg[v];
      mx_node = v;
    }
  }
  vis[mx_node] = true;
  for (int v : adj[mx_node]) {
    ans.push_back(Edge(mx_node, v));
    vis[v] = true;
  }
  for (int v : adj[mx_node]) {
    dfs(v);
  }
  for (auto x : ans) {
    cout << x.u << " " << x.v << "\n";
  }
  return 0;
}
