#include <bits/stdc++.h>   using namespace std;   double tick() {     static clock_t oldt, newt = clock();     double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;     oldt = newt;     return diff;   }   inline long long int read() {     long long int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long int fastExpo(long long int a, long long int n) {     long long int res = 1;     while (n) {       if (n % 2) res = res * a;       n /= 2;       a = a * a;     }     return res;   }   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   vector<int> v[200010];   int col[200010];   vector<int> l, r;   void dfs(int n, int c) {     col[n] = c;     for (int j : v[n]) {       if (col[j] == -1) dfs(j, 1 - c);     }   }   int main() {     int t = read();     while (t--) {       int n = read(), m = read();       while (m--) {         int a, b;         cin >> a >> b;         v[a].push_back(b);         v[b].push_back(a);       }       for (int i = 1; i <= n; i++) col[i] = -1;       dfs(1, 0);       long long int c1 = 0, c2 = 0;       for (int i = 1; i <= n; i++) {         if (col[i])           c1++;         else           c2++;       }       if (c1 <= n / 2) {         cout << c1 << endl;         for (int i = 1; i <= n; i++)           if (col[i]) cout << i <<    ;       } else {         cout << c2 << endl;         for (int i = 1; i <= n; i++)           if (!col[i]) cout << i <<    ;       }       cout << endl;       for (int i = 1; i <= n; i++) v[i].clear(), col[i] = -1;     }     cerr <<  execution time is:   << tick() <<   n ;   }   