#include <bits/stdc++.h>
using namespace std;
const int N(2e5 + 9);
int n, m, ans;
int vis[N];
vector<int> a[N << 1];
queue<int> q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  int s, maxd = 0;
  for (int i = 1; i <= n; i++) {
    if (maxd < a[i].size()) {
      maxd = a[i].size();
      s = i;
    }
  }
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : a[u]) {
      if (vis[v]) continue;
      vis[v] = 1;
      q.push(v);
      cout << u << ' ' << v << endl;
    }
  }
  return 0;
}
