#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > a;
vector<int> vis;
vector<pair<int, int> > ed;
void dfs(int p) {
  vis[p] = 1;
  queue<int> q;
  q.push(p);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto it : a[x]) {
      if (!vis[it]) {
        ed.push_back({x, it});
        q.push(it);
        vis[it] = 1;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  a.resize(n);
  vis.resize(n, 0);
  for (int i = 0; i < m; ++i) {
    int j, k;
    cin >> j >> k;
    a[j - 1].push_back(k - 1);
    a[k - 1].push_back(j - 1);
  }
  int num, x = 0;
  for (int i = 0; i < n; ++i)
    if (a[i].size() > x) {
      x = a[i].size();
      num = i;
    }
  dfs(num);
  for (auto it : ed) {
    cout << it.first + 1 << " " << it.second + 1 << "\n";
  }
}
