#include <bits/stdc++.h>
using namespace std;
bool vis[200007];
vector<vector<int>> v;
int n, m;
void dfs(int x) {
  vis[x] = 1;
  for (auto i : v[x]) {
    if (!vis[i]) {
      cout << x << " " << i << endl;
      dfs(i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  v.resize(n + 1);
  while (m--) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int id, mx = 0;
  for (long long i = 1; i <= (long long)n; ++i) {
    if (v[i].size() >= mx) {
      id = i;
      mx = v[i].size();
    }
  }
  vis[id] = 1;
  for (auto i : v[id]) {
    cout << id << " " << i << endl;
    vis[i] = 1;
  }
  for (auto i : v[id]) dfs(i);
}
