#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
vector<int> sto[maxn];
int pos = 0, cnt = 0;
void bfs() {
  queue<int> que;
  bool vis[maxn] = {0};
  que.push(pos);
  vis[pos] = true;
  while (!que.empty()) {
    int tmp = que.front();
    que.pop();
    for (int i = 0; i < sto[tmp].size(); i++)
      if (vis[sto[tmp][i]] == false) {
        vis[sto[tmp][i]] = true;
        que.push(sto[tmp][i]);
        cout << tmp << " " << sto[tmp][i] << endl;
      }
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    sto[x].push_back(y);
    sto[y].push_back(x);
    if (cnt < sto[x].size()) cnt = sto[x].size(), pos = x;
    if (cnt < sto[y].size()) cnt = sto[y].size(), pos = y;
  }
  bfs();
  return 0;
}
