#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long exp(long long a, long long b, long long m) {
  if (b == 0) return 1;
  if (b == 1) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
vector<long long> G[200200];
vector<long long> parent(200200);
vector<long long> sz(200200);
long long find_set(long long v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void make_set(long long v) {
  parent[v] = v;
  sz[v] = 1;
}
bool union_sets(long long a, long long b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    parent[b] = a;
    sz[a] += sz[b];
    return 1;
  }
  return 0;
}
void mark(long long u) {
  for (auto x : G[u]) {
    if (union_sets(u, x)) {
      cout << u << " " << x << "\n";
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
    make_set(i + 1);
  }
  priority_queue<pair<long long, long long> > pq;
  for (long long i = 1; i <= n; i++) {
    pq.push({G[i].size(), i});
  }
  while (!pq.empty()) {
    mark(pq.top().second);
    pq.pop();
  }
}
