#include <bits/stdc++.h>
using namespace std;
bool node[200005];
vector<int> v[200005];
void bfs(int st) {
  queue<int> q;
  q.push(st);
  node[st] = true;
  int i, j;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (i = 0; i < v[top].size(); i++) {
      if (!node[v[top][i]]) {
        q.push(v[top][i]);
        node[v[top][i]] = true;
        cout << top << " " << v[top][i] << endl;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, i, j, a, b, ma = 0, index;
  cin >> n >> m;
  int no = 0;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (i = 1; i <= n; i++) {
    if (ma < v[i].size()) {
      ma = v[i].size();
      index = i;
    }
  }
  bfs(index);
  return 0;
}
