#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int deg[N], bb;
bool vis[N];
vector<int> g[N];
vector<pair<int, int>> ans;
void Bfs(int node) {
  queue<int> q;
  q.push(node);
  vis[node] = 1;
  while (q.size()) {
    int src = q.front();
    q.pop();
    for (int i = 0; i < g[src].size(); ++i) {
      if (!vis[g[src][i]]) {
        vis[g[src][i]] = 1;
        ans.push_back({src, g[src][i]});
        q.push(g[src][i]);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  int n, m, mx = 0;
  cin >> n >> m;
  for (int i = 0, a, b; i < m; ++i) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  for (int i = 0; i <= n; ++i) {
    if (deg[i] > mx) {
      mx = deg[i];
      bb = i;
    }
  }
  Bfs(bb);
  for (auto i : ans) cout << i.first << " " << i.second << '\n';
  return 0;
}
