#include <bits/stdc++.h>
using namespace std;
vector<int> v[200001];
bool vis[200001];
void fn(int s) {
  int num;
  queue<int> q;
  q.push(s);
  vis[s] = true;
  while (!q.empty()) {
    s = q.front();
    q.pop();
    for (int i = 0; i < v[s].size(); i++) {
      num = v[s][i];
      if (!vis[num]) {
        q.push(num);
        cout << s << " " << num << endl;
        vis[num] = true;
      }
    }
  }
}
int main() {
  int n, m, i, a, b, curr, s;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  curr = 0;
  for (i = 1; i <= n; i++)
    if (v[i].size() > curr) {
      curr = v[i].size();
      s = i;
    }
  fn(s);
}
