#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
vector<long long int> v[200002];
map<long long int, long long int> mp;
void bfs(long long int string) {
  bool vis[200001];
  memset(vis, false, sizeof(vis));
  queue<long long int> q;
  q.push(string);
  vis[string] = true;
  while (!q.empty()) {
    string = q.front();
    q.pop();
    for (auto it : v[string]) {
      if (!vis[it]) {
        cout << string << " " << it << "\n";
        vis[it] = true;
        q.push(it);
      }
    }
  }
}
int main() {
  fast();
  long long int n, m, x, y;
  cin >> n >> m;
  long long int string = 0, ans = -10, tp;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    mp[x] += 1;
    mp[y] += 1;
    tp = max(mp[x], mp[y]);
    if (tp > ans) {
      ans = tp;
      if (mp[x] > mp[y])
        string = x;
      else
        string = y;
    }
  }
  bfs(string);
  return 0;
}
