#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long sub(long long a, long long b, long long p = 1000000007) {
  return (a % p - b % p + p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = mult(r, n, p);
    n = mult(n, n, p);
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
long long n, m, size[200005], link[200005];
vector<long long> v[200005];
vector<pair<long long, long long> > e, ans;
long long find(long long x) {
  while (x != link[x]) {
    link[x] = link[link[x]];
    x = link[x];
  }
  return x;
}
void unite(long long a, long long b) {
  a = find(a);
  b = find(b);
  if (size[a] < size[b]) swap(a, b);
  link[b] = a;
  size[a] += size[b];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    e.push_back({x, y});
  }
  long long mx = 0, ss;
  for (long long i = 1; i <= n; i++) {
    link[i] = i;
    if (mx < v[i].size()) {
      mx = v[i].size();
      ss = i;
    }
  }
  for (auto i : v[ss]) {
    ans.push_back(make_pair(ss, i));
    unite(ss, i);
  }
  for (auto i : e) {
    if (find(i.first) != find(i.second)) {
      ans.push_back(i);
      unite(i.first, i.second);
    }
  }
  for (auto i : ans) cout << i.first << " " << i.second << "\n";
}
