#include <bits/stdc++.h>
using namespace std;
int main() {
  int V, E;
  cin >> V >> E;
  vector<int> g[V + 1];
  int indegree[V + 1];
  for (int i = 1; i <= V; i++) {
    indegree[i] = 0;
  }
  for (int i = 0; i < E; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    indegree[u]++;
    indegree[v]++;
  }
  int maxd = V;
  for (int i = V - 1; i > 0; i--) {
    if (indegree[i] >= indegree[maxd]) {
      maxd = i;
    }
  }
  bool included[V + 1];
  for (int i = 1; i <= V; i++) {
    included[i] = false;
  }
  queue<int> q;
  q.push(maxd);
  included[maxd] = true;
  while (q.empty() != true) {
    int maxd = q.front();
    q.pop();
    for (int u : g[maxd]) {
      if (included[u] == false) {
        included[u] = true;
        q.push(u);
        cout << maxd << " " << u << endl;
      }
    }
  }
  return 0;
}
