#include <bits/stdc++.h>
using namespace std;
long long int n;
queue<long long int> q;
vector<pair<long long int, long long int> > ans;
void bfs(long long int s, vector<long long int> g[]) {
  bool b[n + 1];
  for (long long int i = 0; i < n; i++) {
    b[i] = false;
  }
  b[s] = true;
  q.push(s);
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (long long int i = 0; i < g[x].size(); i++) {
      if (b[g[x][i]] == false) {
        b[g[x][i]] = true;
        ans.push_back(make_pair(x, g[x][i]));
        q.push(g[x][i]);
      }
    }
  }
}
int main() {
  long long int m;
  cin >> n >> m;
  vector<long long int> g[n];
  vector<long long int> deg(n, 0);
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  long long int pos = 0;
  long long int x = deg[0];
  for (long long int i = 1; i < n; i++) {
    if (x < deg[i]) {
      pos = i;
      x = deg[i];
    }
  }
  bfs(pos, g);
  for (long long int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
  }
}
