#include <bits/stdc++.h>
using namespace std;
vector<int> a[200001];
int used[200001];
int main() {
  int n, m, mx = 0, l;
  cin >> n >> m;
  for (int x, y, k = 0; k < m; k++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
    if (a[x].size() > mx) mx = a[x].size(), l = x;
    if (a[y].size() > mx) mx = a[y].size(), l = y;
  }
  queue<int> q;
  q.push(l);
  used[l] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int k : a[x]) {
      if (used[k] == 0) {
        cout << x << ' ' << k << endl;
        used[k] = 1;
        q.push(k);
      }
    }
  }
  return 0;
}
