#include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265358979323;
const double EPS = 1e-12;
const int N = 1e6 + 5;
const int mod = 998244353;
vector<long long> v[N];
long long vis[N], n;
void bfs(long long s) {
  queue<long long> q;
  q.push(s);
  long long ct = 0;
  vis[s] = 1;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (auto it : v[x]) {
      if (!vis[it] && ct < n - 1) {
        vis[it] = 1;
        cout << it << " " << x << "\n";
        ct++;
        q.push(it);
      } else if (ct >= n - 1)
        exit(0);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long m;
  cin >> n >> m;
  long long a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  long long ans = 0, ver;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() > ans) {
      ans = v[i].size();
      ver = i;
    }
  }
  bfs(ver);
  return 0;
}
