#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long Mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b;
  cin >> n >> m;
  vector<int> G[n + 1];
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int vertex = 1;
  for (int i = 1; i <= n; i++) {
    if (G[i].size() > G[vertex].size()) vertex = i;
  }
  set<int> visited;
  queue<int> q;
  visited.insert(vertex);
  q.push(vertex);
  while (q.size() > 0) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      if (visited.find(G[u][i]) == visited.end()) {
        cout << u << " " << G[u][i] << endl;
        q.push(G[u][i]);
        visited.insert(G[u][i]);
      }
    }
  }
  return 0;
}
