#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "}";
  return os;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  if (a.first == b.first) return (a.second >= b.second);
  return (a.first < b.first);
}
vector<long long> primes;
void Seive() {
  vector<long long> seive;
  const long long maxn = 100005;
  seive.resize(maxn, 1);
  for (long long i = 2; i * i < maxn; i++) {
    if (seive[i] == 1) {
      for (long long j = 2 * i; j < maxn; j += i) seive[j] = 0;
    }
  }
  primes.push_back(2);
  for (long long i = 3; i < maxn; i += 2) {
    if (seive[i]) primes.push_back(i);
  }
}
long long power(long long x, long long y, long long m) {
  long long int res = 1;
  x = x % m;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long modinv(long long x, long long mod = 1000000007) {
  return power(x, mod - 2, mod);
}
long long visited[200005];
vector<long long> v[200005];
long long n, m;
vector<pair<long long, long long> > edges;
void bfs(long long src) {
  visited[src] = 1;
  queue<long long> q;
  q.push(src);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (auto it : v[x]) {
      if (visited[it]) continue;
      q.push(it);
      visited[it] = 1;
      edges.push_back({it, x});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k, t, a, b, c, d;
  t = 1;
  cin >> n >> m;
  long long mx = 0, mx_node = 0;
  for (long long(i) = 0; (i) < (m); ++(i))
    cin >> a >> b, v[a].push_back(b), v[b].push_back(a);
  for (int i = 1; i <= n; i++) {
    if (v[i].size() > mx) {
      mx = v[i].size();
      mx_node = i;
    }
  }
  bfs(mx_node);
  for (auto it : edges) cout << it.first << " " << it.second << endl;
}
