#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> g[maxn];
queue<int> q;
int n, m, deg[maxn], vis[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    deg[x]++, deg[y]++;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  int pos = 1;
  for (int i = 2; i <= n; i++)
    if (deg[i] > deg[pos]) pos = i;
  while (!q.empty()) q.pop();
  q.push(pos), vis[pos] = 1;
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (int k = 0; k < deg[i]; k++) {
      int j = g[i][k];
      if (!vis[j]) {
        vis[j] = 1;
        q.push(j);
        cout << i << " " << j << endl;
      }
    }
  }
  return 0;
}
