#include <bits/stdc++.h>
using namespace std;
void dfs(int u, vector<vector<int>>& edges, vector<int>& visited) {
  for (int v : edges[u]) {
    if (!visited[v]) {
      cout << u + 1 << " " << v + 1 << "\n";
      visited[v] = 1;
      dfs(v, edges, visited);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> edges(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  int max_cnt = 0;
  int max_i = 0;
  for (int i = 0; i < n; i++) {
    if (static_cast<int>(edges[i].size()) > max_cnt) {
      max_cnt = edges[i].size();
      max_i = i;
    }
  }
  vector<int> visited(n);
  visited[max_i] = 1;
  vector<int> first;
  for (int v : edges[max_i]) {
    visited[v] = 1;
    cout << max_i + 1 << " " << v + 1 << "\n";
    first.push_back(v);
  }
  for (int f : first) {
    dfs(f, edges, visited);
  }
  return 0;
}
