#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long power(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x);
    }
    n >>= 1;
    if (n != 0) {
      x = (x * x);
    }
  }
  return res;
}
long long powerMOD(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % MOD;
    }
    n >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}
bool mycompare(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first > b.first;
}
bool mycompare1(pair<int, int> &a, pair<int, int> &b) {
  return a.second < b.second;
}
void dfs(vector<long long> gra[], bool vis[], long long cnt[], long long ind,
         vector<long long> &seq, long long a[]) {
  long long i, j;
  vis[ind] = true;
  cnt[ind] = 1;
  seq.push_back(a[ind]);
  for (int i = 0; i < gra[ind].size(); i++) {
    if (!vis[gra[ind][i]]) {
      dfs(gra, vis, cnt, gra[ind][i], seq, a);
      cnt[ind] += cnt[gra[ind][i]];
    }
  }
}
long long par[200000 + 2];
long long getpar(long long x) {
  if (par[x] == x) return x;
  par[x] = getpar(par[x]);
  return par[x];
}
void solve() {
  long long i, j, k, n, m, l, x, p;
  cin >> n >> m;
  vector<long long> a[n];
  for (int i = 0; i < m; i++) {
    cin >> x >> l;
    a[x - 1].push_back(l - 1);
    a[l - 1].push_back(x - 1);
  }
  vector<pair<long long, long long>> b;
  for (int i = 0; i < n; i++) {
    b.push_back({a[i].size(), i});
  }
  sort(b.begin(), b.end(), greater<pair<long long, long long>>());
  l = 0;
  vector<pair<long long, long long>> ans;
  for (int i = 0; i < n; i++) par[i] = i;
  for (int i = 0; i < b.size(); i++) {
    long long u = b[i].second;
    for (auto v : a[u]) {
      long long pu = getpar(u);
      long long pv = getpar(v);
      if (pu != pv) {
        l++;
        par[pv] = pu;
        ans.push_back({u + 1, v + 1});
      }
      if (l == n - 1) break;
    }
    if (l == n - 1) break;
  }
  for (int i = 0; i < n - 1; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1, i;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
