#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int INF = 1000000007;
const long long INF2 = 1000000000000000007;
const long long MOD = 1000000007;
const long long MOD1 = 1864463441;
const int SIZE = 200010;
const double eps = 1e-9;
const long double pi = acos(-1.0);
long long n, m, k, x, y, z, v, v1, sum, med, a, b, cnt, c, rs, ind, ind1, q, l,
    r, d, sz, mx, mi, bf, bf1;
long long ar[SIZE], kekw[110];
bool fl, fl1, lose, used[SIZE];
string s, t;
bool cmp(int a, int b) { return a > b; }
set<int> st;
vector<int> g[SIZE];
map<pair<int, int>, bool> mp;
queue<int> qq;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> v >> v1;
    v--;
    v1--;
    g[v].push_back(v1);
    g[v1].push_back(v);
    mp[make_pair(v, v1)] = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (mx < g[i].size()) {
      mx = g[i].size();
      x = i;
    }
  }
  qq.push(x);
  used[x] = 1;
  while (!qq.empty()) {
    v = qq.front();
    qq.pop();
    for (auto& i : g[v]) {
      if (!used[i]) {
        used[i] = 1;
        cout << v + 1 << " " << i + 1 << endl;
        qq.push(i);
      }
    }
  }
  return 0;
}
