#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > grafo[435544];
bool vis[435544], invalid[435544];
int arrpa[435544];
int findpa(int num) {
  if (arrpa[num] == num)
    return num;
  else
    return arrpa[num] = findpa(arrpa[num]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 435544; ++i) {
    vis[i] = invalid[i] = 0;
    arrpa[i] = i;
  }
  int n, m;
  cin >> n >> m;
  int iz, der;
  vector<pair<int, int> > lst;
  for (int i = 0; i < m; ++i) {
    cin >> iz >> der;
    lst.push_back(pair<int, int>(iz, der));
    grafo[iz].push_back(pair<int, int>(der, i));
    grafo[der].push_back(pair<int, int>(iz, i));
  }
  int cnt, num, maxx = 0;
  for (int i = 1; i <= n; ++i) {
    cnt = grafo[i].size();
    if (cnt > maxx) {
      maxx = cnt;
      num = i;
    }
  }
  int hijo, pos, pa1, pa2;
  for (int i = 0; i < grafo[num].size(); ++i) {
    hijo = grafo[num][i].first;
    pos = grafo[num][i].second;
    arrpa[hijo] = num;
  }
  for (int i = 0; i < lst.size(); ++i) {
    iz = lst[i].first;
    der = lst[i].second;
    pa1 = findpa(iz);
    pa2 = findpa(der);
    if (pa1 == pa2 && iz != num && der != num) continue;
    arrpa[pa1] = pa2;
    cout << iz << " " << der << endl;
  }
}
