#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q) > 0){
        int x = q.front();
        q.pop();
        debug2(x, col[x])
        if(col[x] == 0) col[x] = 2;
        trace(x, col[x], col);
        for(int v : g[x]){
            debug2(x,v)
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
                debug(v)
            }
        }
    }
}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    //n = rand() % 10 + 2;
    //m =
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.assign(n+1, 0);
    col.assign(n+1, 0);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.assign(n+1, 0);
        col.assign(n+1, 0);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    }
    assert(sz(ans) > 0);
    assert(sz(ans) <= n/2 );
    fornn(i,1,n+1) assert(col[i] > 0);
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q) > 0){
        int x = q.front();
        q.pop();
        debug2(x, col[x])
        if(col[x] == 0) col[x] = 2;
        trace(x, col[x], col);
        for(int v : g[x]){
            debug2(x,v)
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
                debug(v)
            }
        }
    }
    /*
    for(int v: g[u]){
        if(vis[u] == 0) dfs(u);
        else if(vis[u] == 1){

        }else if(vis[u] == 2){

        }
    }
    vis[u] = 2;
    */

}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    //n = rand() % 10 + 2;
    //m =
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.assign(n+1, 0);
    col.assign(n+1, 0);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.assign(n+1, 0);
        col.assign(n+1, 0);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    }
    //assert(sz(ans) > 0);
    //assert(sz(ans) <= n/2 );
    //fornn(i,1,n+1) assert(col[i] > 0);
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q) > 0){
        int x = q.front();
        q.pop();
        debug2(x, col[x])
        if(col[x] == 0) col[x] = 2;
        trace(x, col[x], col);
        for(int v : g[x]){
            debug2(x,v)
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
                debug(v)
            }
        }
    }
    /*
    for(int v: g[u]){
        if(vis[u] == 0) dfs(u);
        else if(vis[u] == 1){

        }else if(vis[u] == 2){

        }
    }
    vis[u] = 2;
    */

}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    //n = rand() % 10 + 2;
    //m =
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.assign(n+1, 0);
    col.assign(n+1, 0);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.assign(n+1, 0);
        col.assign(n+1, 0);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    }
    assert(sz(ans) > 0);
    //assert(sz(ans) <= n/2 );
    fornn(i,1,n+1) assert(col[i] > 0);
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q) > 0){
        int x = q.back();
        q.pop();
        if(col[x] == 0) col[x] = 2;
        for(int v : g[x]){
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
            }
        }
    }
    /*
    for(int v: g[u]){
        if(vis[u] == 0) dfs(u);
        else if(vis[u] == 1){

        }else if(vis[u] == 2){

        }
    }
    vis[u] = 2;
    */

}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.assign(n+1, 0);
    col.assign(n+1, 0);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.assign(n+1, 0);
        col.assign(n+1, 0);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    }
    assert(sz(ans) > 0);
    //assert(sz(ans) <= n/2 );
    fornn(i,1,n+1) assert(col[i] > 0);
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q) > 0){
        int x = q.back();
        q.pop();
        if(col[x] == 0) col[x] = 2;
        for(int v : g[x]){
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
            }
        }
    }
    /*
    for(int v: g[u]){
        if(vis[u] == 0) dfs(u);
        else if(vis[u] == 1){

        }else if(vis[u] == 2){

        }
    }
    vis[u] = 2;
    */

}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.assign(n+1, 0);
    col.assign(n+1, 0);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.assign(n+1, 0);
        col.assign(n+1, 0);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] != 1) ans.pb(i);
    }
    assert(sz(ans) > 0);
    assert(sz(ans) <= n/2 );
    //fornn(i,1,n+1) assert(col[i] > 0);
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define LOCAL_PROJECTx

#ifdef LOCAL_PROJECT
#include "debug.h"
#else
#define debug(x)
#define debuga(a, n)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, w)
template <typename Arg, typename... Args>
void trace(Arg&& arg, Args&&... args){}
#endif

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(c) ((int) c.size())
#define forn(i,m) for(int i=0;i<(int)(m);i++)
#define fornn(i,n,m) for(int i=n;i<(int)(m);i++)
#define forb(i,n) for(int i=n-1;i>=0;i--)
#define forbn(i,n,m) for(int i=m-1;i>=(int)(n);i--)
#define fora(it, c) for(const auto &it: c)
#define mem(a,b) memset(a,b,sizeof(a))
#define upair(a,b)  make_pair(min(a,b),max(a,b))
#define fi first
#define se second
#define mmax(a,b) a = (a) > (b) ? (a) : (b)
#define mmin(a,b) a = (a) < (b) ? (a) : (b)
#define abs(x) (((x) < 0) ? -(x) : (x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define has(c,x) (c.find(x)!=c.end())
#define pw(x) (1LL << (x))
#define ibit(x,i) (x & pw(i))
#define sbit(x,i) (x |= pw(i))

typedef stringstream sstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<double,double> pdd;
typedef pair<long,long> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

inline int ni(){ int x; scanf("%d",&x);   return x; }
inline ll  nl() { ll  x; scanf("%lld",&x); return x; }

// variadics
template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, max_(last...)); }

template <class T, class S> void outvp(vector<pair<T,S>> &v){
    for(pair<T,S> x: v) cout << x.first << " " << x.second << endl;
}
template <typename T> void outv(vector<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outs(set<T> &v){
    for(T x: v) cout << x << " "; cout << endl;
}
template <typename T> void outm(map<T, int> &v, int n=1){
    for(T &x: v) cout << (n==1 ? x.first : x.second) << " "; cout << endl;
}
template <typename T> void finalize(T x){
    cout << x << endl;
    exit(0);
}
void yesno(int x, int last = 1){
    cout << (x ? "YES" : "NO") << endl;
    if(last) exit(0);
}
template <typename T> void readv(vector<T> &v, int n){
    v = vector<T>(n);
    forn(i,n) cin >> (v[i]);
}
template <typename T> void reads(set<T> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v.insert(x);
    }
}
template <typename T> void readm(map<T, int> &v, int n){
    T x;
    forn(i,n){
        cin >> x;
        v[x]++;
    }
}

template <typename Arg, typename... Args>
void read(Arg&& arg, Args&&... args)
{
    cin >> std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cin >> std::forward<Args>(args)),0)...};
}

ll pwr(ll base, ll p, ll mod){
    ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;
const int oo = 0x3f3f3f3f;
const ll  OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int dx[8]={0,1, 0,-1,-1,1,-1, 1};
const int dy[8]={1,0,-1, 0,-1,1, 1,-1};
const int dsx[4]={0,1, 0,-1};
const int dsy[4]={1,0,-1, 0};

/*************************************************************************/

const int maxn=200123;

vvi g;
vi vis;
vi col;
void _build(){

}

void bfs(int u){
    vis[u] = 1;
    queue<int> q;
    q.push(u);
    while(sz(q)){
        int x = q.back();
        q.pop();
        if(col[x] == 0) col[x] = 2;
        for(int v : g[x]){
            if(col[x] == 2) mmax(col[v], 1);
            if(vis[v] == 0){
                vis[v]++;
                q.push(v);
            }
        }
    }
    /*
    for(int v: g[u]){
        if(vis[u] == 0) dfs(u);
        else if(vis[u] == 1){

        }else if(vis[u] == 2){

        }
    }
    vis[u] = 2;
    */

}

void _solve(){
    g.clear();
    int n,m;
    read(n,m);
    g.resize(n+1);
    forn(i,m){
        int u,v; read(u,v); //u--, v--
        g[u].pb(v);
        g[v].pb(u);
    }
    vis.clear();
    vis.resize(n+1);
    col.clear();
    col.resize(n+1);
    bfs(1);
    vi ans;
    fornn(i,1,n+1) if(col[i] == 2) ans.pb(i);
    trace(n,m,g);
    trace(vis);
    trace(col);
    trace(ans);
    if(sz(ans) > n/2){
        vis.clear();
        vis.resize(n+1);
        col.clear();
        col.resize(n+1);
        bfs(g[1][0]);
        ans.clear();
        fornn(i,1,n+1) if(col[i] == 2) ans.pb(i);
    }
    cout << sz(ans) << endl;
    outv(ans);

}

/*************************************************************************/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.precision(15);
    bool GOOGLE = false;
    _build();
    int qq=1;
    if(1) cin>>qq;
    forn(i,qq){
        if(GOOGLE) cout<<"Case #"<<i+1<<": ";
        _solve();
        //cout<<endl;
        //fprintf (stderr, "%d / %d = %.2f | %.2f\n", i+1, qq, (double)clock () / CLOCKS_PER_SEC, ((double)clock () / (i+1) * qq) / CLOCKS_PER_SEC);
    }

}

/*************************************************************************/
/*
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>
1-4
10-17
20-22

*/


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int color[N];

void dfs(int s,int v)
{
    vis[s]=1;
    if(1)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2&&(!v))v=1;
        if(cnt==0){int x = 0;for(auto z : vec[s])if(color[z]==1)x=1;
        if(!x)color[s]=1;return;}
    }
    color[s]=v;
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(color,0,n*sizeof(color[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,0);
        int cnt=0;
        for(int i = 0;i<n;i++)if(color[i]==1)cnt++;
        cout<<cnt<<endl;
        for(int i = 0;i<n;i++)if(color[i]==1)cout<<i+1<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int lev[N];
int cnt_lev[N];

void dfs(int s)
{
    vis[s]=1;
    queue<int>q;
    q.push(s);
    int x=0;
    lev[s]=1;
    cnt_lev[1]=1;
    while(!q.empty())
    {
        int z = q.front();
        q.pop();
        for(auto i : vec[z])if(!vis[i])
        {
            vis[i]=1;
            lev[i]=lev[z]+1;
            //cout<<"            "<<i<<" "<<lev[i]<<endl;
            cnt_lev[lev[i]]++;
            q.push(i);
            //max_lev=max(max_lev,lev[i])
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(lev,0,n*sizeof(lev[0]));
        memset(cnt_lev,0,n*sizeof(cnt_lev[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0);
        int cnt=0,cnt2=0;
        for(int i = 0;i<n;i+=2)cnt2+=cnt_lev[i];
        for(int i = 1;i<n;i+=2)cnt+=cnt_lev[i];
        int d=1;
        if(cnt2<cnt)d=0;
        cout<<"                 "<<min(cnt,cnt2)<<endl;
        for(int  i = 0;i<n;i++)
        {
            if(((lev[i])&(1))==d)
            {
                cout<<i+1<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
vector<int>ans;

void dfs(int s,int v)
{
    vis[s]=1;
    if(1)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2&&(!v))v=1;
        if(cnt==0)return;
    }
    if(v)ans.pb(s);
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        ans.clear();
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,1);
        cout<<endl;;
        cout<<ans.size()<<endl;
        for(auto i : ans)cout<<i+1<<" ";cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int color[N];

void dfs(int s,int v)
{
    vis[s]=1;
    if(1)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2&&(!v))v=1;
        if(cnt==0){int x = 0;for(auto z : vec[s])if(color[z]==1)x=1;
        if(!x)color[s]=1;return;}
    }
    color[s]=v;
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(color,0,n*sizeof(color[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,1);
        int cnt=0;
        for(int i = 0;i<n;i++)if(color[i]==1)cnt++;
        cout<<cnt<<endl;
        for(int i = 0;i<n;i++)if(color[i]==1)cout<<i+1<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
vector<int>ans;

void dfs(int s,int v)
{
    vis[s]=1;
    if(1)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2&&(v))v=1;
        if(cnt==0)return;
    }
    if(v)ans.pb(s);
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        ans.clear();
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,1);
        cout<<endl;;
        cout<<ans.size()<<endl;
        for(auto i : ans)cout<<i+1<<" ";cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int lev[N];
int cnt_lev[N];

void dfs(int s)
{
    vis[s]=1;
    queue<int>q;
    q.push(s);
    int x=0;
    lev[s]=1;
    cnt_lev[1]=1;
    while(!q.empty())
    {
        int z = q.front();
        q.pop();
        for(auto i : vec[z])if(!vis[i])
        {
            vis[i]=1;
            lev[i]=lev[z]+1;
            //cout<<"            "<<i<<" "<<lev[i]<<endl;
            cnt_lev[lev[i]]++;
            q.push(i);
            //max_lev=max(max_lev,lev[i])
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(lev,0,(n+1)*sizeof(lev[0]));
        memset(cnt_lev,0,(n+1)*sizeof(cnt_lev[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0);
        int cnt=0,cnt2=0;
        for(int i = 0;i<=n;i+=2)cnt2+=cnt_lev[i];
        for(int i = 1;i<=n;i+=2)cnt+=cnt_lev[i];
        int d=1;
        if(cnt2<cnt)d=0;
        cout<<"                 "<<min(cnt,cnt2)<<endl;
        for(int  i = 0;i<n;i++)
        {
            if(((lev[i])&(1))==d)
            {
                cout<<i+1<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
vector<int>ans;

void dfs(int s,int v)
{
    vis[s]=1;
    if(v==0)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2)v=1;
        if(cnt==0)return;
    }
    if(v)ans.pb(s);
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        ans.clear();
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,1);
        cout<<endl;;
        cout<<ans.size()<<endl;
        for(auto i : ans)cout<<i+1<<" ";cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int color[N];

void dfs(int s,int v)
{
    vis[s]=1;
    if(1)
    {
        int cnt=0;
        for(auto x : vec[s])if(!vis[x])cnt++;
        if(cnt>2&&(!v))v=1;
        if(cnt==0){int x = 0;for(auto z : vec[s]){if(color[z]==1)x=1;

        }if(!x)color[s]=1;return;
    }
    color[s]=v;
    for(auto i : vec[s])if(!vis[i])
    {
        dfs(i,(v^1));
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(color,0,n*sizeof(color[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0,1);
        int cnt=0;
        for(int i = 0;i<n;i++)if(color[i]==1)cnt++;
        cout<<cnt<<endl;
        for(int i = 0;i<n;i++)if(color[i]==1)cout<<i+1<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pb push_back

ll n,m;

int ck(int pos)
{
    if(pos<0)return 0;
    int x = (ck(pos-1)||ck(pos-2)||ck(pos-m));
    return (x^1);
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {

        cin >> n >> m;
        int z = (ck(n-1)||ck(n-2)||ck(n-m));
        if(z==1)
        {
            cout<<"Alice"<<endl;
        }
        else
        {
            cout<<"Bob"<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 200100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int lev[N];
int cnt_lev[N];

void dfs(int s)
{
    vis[s]=1;
    queue<int>q;
    q.push(s);
    int x=0;
    lev[s]=1;
    cnt_lev[1]=1;
    while(!q.empty())
    {
        int z = q.front();
        q.pop();
        for(auto i : vec[z])if(!vis[i])
        {
            vis[i]=1;
            lev[i]=lev[z]+1;
            //cout<<"            "<<i<<" "<<lev[i]<<endl;
            cnt_lev[lev[i]]++;
            q.push(i);
            //max_lev=max(max_lev,lev[i])
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(lev,0,(n+1)*sizeof(lev[0]));
        memset(cnt_lev,0,(n+1)*sizeof(cnt_lev[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0);
        int cnt=0,cnt2=0;
        for(int i = 0;i<=n;i+=2)cnt2+=cnt_lev[i];
        for(int i = 1;i<=n;i+=2)cnt+=cnt_lev[i];
        int d=1;
        if(cnt2<cnt)d=0;
        cout<<"                 "<<min(cnt,cnt2)<<endl;
        for(int  i = 0;i<n;i++)
        {
            if(((lev[i])&(1))==d)
            {
                cout<<i+1<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define N 100100
#define pb push_back

vector<int>vec[N];
int  vis[N];
int lev[N];
int cnt_lev[N];

void dfs(int s)
{
    vis[s]=1;
    queue<int>q;
    q.push(s);
    int x=0;
    lev[s]=1;
    cnt_lev[1]=1;
    while(!q.empty())
    {
        int z = q.front();
        q.pop();
        for(auto i : vec[z])if(!vis[i])
        {
            vis[i]=1;
            lev[i]=lev[z]+1;
            //cout<<"            "<<i<<" "<<lev[i]<<endl;
            cnt_lev[lev[i]]++;
            q.push(i);
            //max_lev=max(max_lev,lev[i])
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    ll T=1;
    cin >> T;
    while(T--)
    {
        int n,M;
        cin >> n >> M;
        memset(vis,0,n*sizeof(vis[0]));
        memset(lev,0,(n+1)*sizeof(lev[0]));
        memset(cnt_lev,0,(n+1)*sizeof(cnt_lev[0]));
        for(int i = 0;i<n;i++)vec[i].clear();
        for(int i = 1;i<=M;i++)
        {
            int u,v;
            cin >> u >> v;
            --u;--v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(0);
        int cnt=0,cnt2=0;
        for(int i = 0;i<=n;i+=2)cnt2+=cnt_lev[i];
        for(int i = 1;i<=n;i+=2)cnt+=cnt_lev[i];
        int d=1;
        if(cnt2<cnt)d=0;
        cout<<"                 "<<min(cnt,cnt2)<<endl;
        for(int  i = 0;i<n;i++)
        {
            if(((lev[i])&(1))==d)
            {
                cout<<i+1<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;};
Node edge[maxn*2];
void add(int x,int y)
{
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    newpos[now ++] = x;
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            DFS(edge[k].to);
        }
    }
}

int MDS() {
    bool s[maxn] = {0};
    bool set[maxn] = {0};
    int ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        int t = newpos[i];
        if(!s[t]) {
            if(! set[ pre[t] ]) {
                set[ pre[t] ] = true;
                ans ++;
				p[ans]=pre[t] ;
            }
            s[t] = true;
            s[ pre[t] ] = true;
            s[ pre[ pre[t] ] ] = true;
        }
    }
    return ans;
}

int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(edge, 0, sizeof(edge));
    	now=0;
    cnt=0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<=n;i++)
	{
		p[i]=pre[i]=visit[i]=newpos[i]=0;
		head[i]=-1;
	}
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
    now = 0;
    visit[1] = true;
    pre[1] = 1;
    DFS(1);
    int g=MDS();
    printf("%d\n",g);
    printf("%d",p[1]);
    for(int i=2;i<=g;i++)
    {
    	printf(" %d",p[i]);
	}
	printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;};
Node edge[maxn*2];
void add(int x,int y)
{
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    newpos[now ++] = x;
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            DFS(edge[k].to);
        }
    }
}

int MDS() {
    bool s[maxn] = {0};
    bool set[maxn] = {0};
    int ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        int t = newpos[i];
        if(!s[t]) {
            if(! set[ pre[t] ]) {
                set[ pre[t] ] = true;
                ans ++;
				p[ans]=pre[t] ;
            }
            s[t] = true;
            s[ pre[t] ] = true;
            s[ pre[ pre[t] ] ] = true;
        }
    }
    return ans;
}

int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    now=0;
    cnt=0;
    edge[0].to=edge[0].next=0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<=n;i++)
	{
		p[i]=pre[i]=visit[i]=newpos[i]=edge[(i+1)*2].to=edge[(i+1)*2].next=0;
		head[i]=-1;
	}
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
    now = 0;
    visit[1] = true;
    pre[1] = 1;
    DFS(1);
    int g=MDS();
    printf("%d\n",g);
    printf("%d",p[1]);
    for(int i=2;i<=g;i++)
    {
    	printf(" %d",p[i]);
	}
	printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now,ans;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;int now;};
Node edge[maxn*2];
void add(int x,int y)
{
	edge[cnt].now=x;
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            if(!p[pre[x]]){
            	p[x]=true;ans++;
            	p[ans]=x;
			}
            DFS(edge[k].to);
        }
    }
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(p,0,sizeof(p));
    	memset(pre,0,sizeof(pre));
    	memset(head,-1,sizeof(head));
    	memset(visit, false, sizeof(visit));
    	memset(edge, false, sizeof(edge));
    	now=0;
    	ans=0;
    cnt=0;
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
	pre[1]=1;
	DFS(1);
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)printf("%d ",p[i]);
	printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>
#include<queue>
using namespace std;
const int maxn = 2e5+10;
int ans;
int a[maxn],b[maxn],c[maxn];
int main() {
    int t,x,y;
    scanf("%d",&t);
    while(t--)
    {
    	ans=0;
    	int n,m;
    	memset(a,0,sizeof(a));
    	memset(b,0,sizeof(b));
    	memset(c,0,sizeof(c));
    	scanf("%d %d",&n,&m);
    	for(int i=0;i<m;i++)
    	{
    		scanf("%d %d",&x,&y);
    		if(b[x]==1&&b[y]==1)continue;
    		if(a[x]==1&&a[y]==0&&b[x]==0){
    			b[y]=1;
    			ans++;
    			c[ans]=y;
    			a[y]=1;
			}
			else if(a[x]==0&&a[y]==1&&b[y]==0){
				a[x]=b[x]=1;
				ans++;
				c[ans]=x;
			}
			else {
				a[x]=a[y]=1;
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=ans;i++)printf("%d ",c[i]);
		printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now,ans;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;int now;};
Node edge[maxn*2];
void add(int x,int y)
{
	edge[cnt].now=x;
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            if(!p[pre[x]]){
            	p[x]=true;
            	printf("%d ",x);
			}
            DFS(edge[k].to);
        }
    }
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(p,0,sizeof(p));
    	memset(pre,0,sizeof(pre));
    	memset(head,-1,sizeof(head));
    	memset(visit, false, sizeof(visit));
    	memset(edge, false, sizeof(edge));
    	now=0;
    	ans=0;
    cnt=0;
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
	pre[1]=1;
	printf("%d\n",n/2);
	DFS(1);
	printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>
const int maxn = 2e5+10;
using namespace std;
vector<int>U[maxn],ans[2];
int n,m;
int T;
int vis[maxn];
void dfs(int n,int ind)
{
	vis[n]=1;
	ans[ind].push_back(n);
	for(auto nx:U[n]){
		if(vis[nx])continue;
		dfs(nx,ind^1);
	}
	return;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			U[i].clear();
			vis[i]=0;
		}
		ans[0].clear();ans[1].clear();
		for(int i=1;i<=m;i++)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			U[a].push_back(b);
			U[b].push_back(a);
		}
		dfs(1,0);
		if(ans[0].size()>ans[1].size())
		{swap(ans[0],ans[1]);
		}
		printf("%d\n",ans[0].size());
		for(auto it:ans[0])printf("%d ",it);
		printf("\n");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;};
Node edge[maxn*2];
void add(int x,int y)
{
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    newpos[now ++] = x;
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            DFS(edge[k].to);
        }
    }
}

int MDS() {
    bool s[maxn] = {0};
    bool set[maxn] = {0};
    int ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        int t = newpos[i];
        if(!s[t]) {
            if(! set[ pre[t] ]) {
                set[ pre[t] ] = true;
                printf("%d ",t);
            }
            set[t] = true;
            s[ pre[t] ] = true;
            s[t]=true;
        }
    }
    return ans;
}

int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(p,0,sizeof(p));
    	memset(pre,0,sizeof(pre));
    	memset(head,-1,sizeof(head));
    	memset(visit, false, sizeof(visit));
    	memset(newpos, false, sizeof(newpos));
    	memset(edge, false, sizeof(edge));
    	now=0;
    cnt=0;
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
    now = 0;
    visit[1] = true;
    pre[1] = 1;
    DFS(1);
    printf("%d\n",n/2);
    MDS();
    printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>
#include<queue>
using namespace std;
const int maxn = 2e5+10;
int ans;
int a[maxn],b[maxn],c[maxn];
int main() {
    int t,x,y;
    scanf("%d",&t);
    while(t--)
    {
    	ans=0;
    	int n,m;
    	scanf("%d %d",&n,&m);
    	for(int i=0;i<=n;i++){
    		a[i]=0;
    		b[i]=0;
		}
    	for(int i=0;i<m;i++)
    	{
    		scanf("%d %d",&x,&y);
    		if(b[x]==1&&b[y]==1)continue;
    		if(a[x]==1&&a[y]==0&&b[x]==0){
    			b[y]=1;
    			ans++;
    			c[ans]=y;
    			a[y]=1;
			}
			else if(a[x]==0&&a[y]==1&&b[y]==0){
				a[x]=b[x]=1;
				ans++;
				c[ans]=x;
			}
			else {
				a[x]=a[y]=1;
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=ans;i++)printf("%d ",c[i]);
		printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now,ans;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;int now;};
Node edge[maxn*2];
void add(int x,int y)
{
	edge[cnt].now=x;
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            if(!p[pre[x]]){
            	p[x]=true;
            	printf("%d ",x);
			}
            DFS(edge[k].to);
        }
    }
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    now=0;
    cnt=0;
    edge[0].to=edge[0].next=0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<=n;i++)
	{
		p[i]=pre[i]=visit[i]=newpos[i]=edge[(i+1)*2].to=edge[(i+1)*2].next=0;
		head[i]=-1;
	}
    ans=0;
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
	pre[1]=1;
	printf("%d\n",n/2);
	DFS(1);
	printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int ans;
int n, m;
int p[maxn];
int head[maxn];
int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(p,0,sizeof(p));
    	memset(head,0,sizeof(head));
    	ans=0;
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		if(!p[x]&&!p[y]){
			ans++;
			p[x]=true;
			p[y]=true;
			head[ans]=x;
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)printf("%d ",head[i]);
	printf("\n");
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5+10;
int pre[maxn];
bool visit[maxn];
int newpos[maxn];
int now;
int n, m,cnt;
int p[maxn];
int head[maxn];
struct Node {int to; int next;};
Node edge[maxn*2];
void add(int x,int y)
{
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}

void DFS(int x) {
    newpos[now ++] = x;
    for(int k = head[x]; k != -1; k = edge[k].next) {
        if(!visit[ edge[k].to ]) {
            visit[ edge[k].to ] = true;
            pre[edge[k].to] = x;
            DFS(edge[k].to);
        }
    }
}

int MDS() {
    bool s[maxn] = {0};
    bool set[maxn] = {0};
    int ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        int t = newpos[i];
        if(!s[t]) {
            if(! set[ pre[t] ]) {
                set[ pre[t] ] = true;
                ans ++;
				p[ans]=pre[t] ;
            }
            s[t] = true;
            s[ pre[t] ] = true;
            s[ pre[ pre[t] ] ] = true;
        }
    }
    return ans;
}

int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
    	memset(p,0,sizeof(p));
    	memset(pre,0,sizeof(pre));
    	memset(head,-1,sizeof(head));
    	memset(visit, false, sizeof(visit));
    	memset(newpos, false, sizeof(newpos));
    	memset(edge, false, sizeof(edge));
    	now=0;
    cnt=0;
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y);
		add(y,x);
	}
    now = 0;
    visit[1] = true;
    pre[1] = 1;
    DFS(1);
    int g=MDS();
    printf("%d\n",g);
    printf("%d",p[1]);
    for(int i=2;i<=g;i++)
    {
    	printf(" %d",p[i]);
	}
	printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#include<queue>
using namespace std;
const int maxn = 2e5+10;
int ans,cnt;
int head[maxn];
int f[maxn],p[maxn];
bool visit[maxn];
struct Node{
	int to,next;
};
Node edge[maxn*2];
void add(int u,int v)
{
	edge[cnt].to=v;
	edge[cnt].next=head[u];
	head[u]=cnt++;
}
void bfs(int x)
{
	visit[x]=true;
	queue<int>que;
	ans=0;
	que.push(x);
	memset(f,0,sizeof(f));
	memset(p,0,sizeof(p));
	p[1]=0;
	while(!que.empty())
	{
		int now=que.front();
		que.pop();
		for(int i=head[now];i!=-1;i=edge[i].next)
		{
			if(!visit[edge[i].to])
			{
				visit[edge[i].to]=true;
				if(p[now]);else
				{
					ans++;
					p[edge[i].to]=ans;
					p[now]=ans;
					f[ans]=edge[i].to;
				}
				que.push(edge[i].to);
			}
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
	{
		printf("%d ",f[i]);
	}
	printf("\n");
	return ;
}
int main() {
    int t,x,y;
    scanf("%d",&t);
    while(t--)
    {
    	cnt=0;
    	memset(edge,0,sizeof(edge));
    	memset(visit,0,sizeof(visit));
    	memset(head,-1,sizeof(head));
    	int n,m;
    	scanf("%d %d",&n,&m);
    	for(int i=0;i<m;i++)
    	{
    		scanf("%d %d",&x,&y);
    		add(x,y);
    		add(y,x);
		}
		bfs(1);
	}
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<cstdlib>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;

const int N = 2e5 + 10;
bool vis[N];
vector<int> g[N];
int n, m;
vector<int> ans1, ans2;
void solve(int v)
{
	for (int i = 0; i < g[v].size(); i++)
	{
		vis[g[v][i]] = true;
		ans2.push_back(g[v][i]);
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int cnt = 0;
		cin >> n >> m;
		for (int i = 0; i <= n; i++)
			g[i].clear();
		ans1.clear(), ans2.clear();
		memset(vis, false, sizeof(vis));
		while (m--)
		{
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
		{
			if (!vis[i]){
				solve(i);
				cnt++;
				ans1.push_back(i);
			}
		}
		if (cnt <= n / 2)
		{
			cout << cnt << endl;
			for (auto i : ans1)
				cout << i << ' ';
		}
		else
		{
			cout << n - cnt << endl;
			for (auto i : ans2)
				cout << i << ' ';
		}
		cout << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<cstdlib>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;

const int N = 2e5 + 10;
bool vis[N];
vector<int> g[N];
int n, m;
vector<int> ans1, ans2;
void solve(int v)
{
	for (auto &i:g[v])
	{
		if (!vis[i]){
			vis[i] = true;
			ans2.push_back(i);
		}
	}
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int cnt = 0;
		scanf("%d%d", &n, &m);
		for (int i = 0; i <= n; i++)
			g[i].clear();
		ans1.clear(), ans2.clear();
		memset(vis, false, sizeof(vis));
		while (m--)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
		{
			if (!vis[i]){
				solve(i);
				cnt++;
				ans1.push_back(i);
			}
		}
		if (cnt <= n / 2)
		{
			printf("%d\n", cnt);
			for (auto &i : ans1)
				printf("%d ", i);
		}
		else
		{
			printf("%d\n",n- cnt);
			for (auto &i : ans2)
				printf("%d ", i);
		}
		puts("");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<cstdlib>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;

const int N = 2e5 + 10;
bool vis[N];
vector<int> g[N];
int n, m;
vector<int> ans1, ans2;
void solve(int v)
{
	for (int i = 0; i < g[v].size(); i++)
	{
		if (!vis[g[v][i]]){
			vis[g[v][i]] = true;
			ans2.push_back(g[v][i]);
		}
	}
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int cnt = 0;
		scanf("%d%d", &n, &m);
		for (int i = 0; i <= n; i++)
			g[i].clear();
		ans1.clear(), ans2.clear();
		memset(vis, false, sizeof(vis));
		while (m--)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
		{
			if (!vis[i]){
				solve(i);
				cnt++;
				ans1.push_back(i);
			}
		}
		if (cnt <= n / 2)
		{
			printf("%d\n", cnt);
			for (auto &i : ans1)
				printf("%d ", i);
		}
		else
		{
			printf("%d\n",n- cnt);
			for (auto &i : ans1)
				printf("%d ", i);
		}
		puts("");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<cstdlib>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;

const int N = 2e5 + 10;
bool vis[N];
vector<int> g[N];
int n, m;
void solve(int v)
{
	for (int i = 0; i < g[v].size(); i++)
		vis[g[v][i]] = true;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int cnt = 0;
		cin >> n >> m;
		for (int i = 0; i <= n; i++)
			g[i].clear();
		memset(vis, false, sizeof(vis));
		while (m--)
		{
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int i = 1; i <= n; i++)
		{
			if (!vis[i])
			{
				solve(i);
				cnt++;
			}
		}
		if (cnt <= n / 2)
		{
			cout << cnt << endl;
			for (int i = 1; i <= n;i++)
				if (!vis[i]) cout << i << ' ';
		}
		else
		{
			cout << n - cnt << endl;
			for (int i = 1; i <= n; i++)
				if (vis[i]) cout << i << ' ';
		}
		cout << endl;
	}
	return 0;
}


import java.io.*;
import java.util.*;

public class CurrencySum {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        if (a[0] == 1){
            System.out.println(-1);
        } else {
            System.out.println(1);
        }

    }
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}


import java.util.Scanner;

public class BankNotes {

	private void run() {
		String[] notesValues = readLine().split(" ");

		boolean has1 = false;
		for (int i = 0; i < notesValues.length; i++) {
			String note = notesValues[i];
			if ("1".equals(note)) {
				has1 = true;
			}
		}

		System.out.println(has1 ? "-1" : "1");
	}

	public static void main(String[] args) {
		BankNotes notes = new BankNotes();
		notes.run();
		notes.close();
	}

	private Scanner sc;

	private BankNotes() {
		this.sc = new Scanner(System.in);
	}

	private String readLine() {
		if (sc.hasNextLine()) {
			return (sc.nextLine());
		} else {
			return null;
		}
	}

	private void close() {
		try {
			sc.close();
		} catch (Exception e) {
			//log
		}
	}
}


import java.util.Scanner;

public class BankNotes {

	private void run() {
		String[] notesValues = readLine().split(" ");

		boolean has1 = false;
		for (int i = 0; i < notesValues.length; i++) {
			String note = notesValues[i];
			if ("1".equals(note)) {
				has1 = true;
			}
		}

		System.out.println(has1 ? "-1" : "1");
	}

	public static void main(String[] args) {
		BankNotes notes = new BankNotes();
		notes.run();
		notes.close();
	}

	private Scanner sc;

	private BankNotes() {
		this.sc = new Scanner(System.in);
        while(sc.hasNextLine()) System.out.println(sc.nextLine());
	}

	private String readLine() {
		if (sc.hasNextLine()) {
			return (sc.nextLine());
		} else {
			return null;
		}
	}

	private void close() {
		try {
			sc.close();
		} catch (Exception e) {
			//log
		}
	}
}


import java.util.Scanner;

public class BankNotes {

	private void run() {
		readLine();
		String[] notesValues = readLine().split(" ");

		boolean has1 = false;
		for (int i = 0; i < notesValues.length; i++) {
			String note = notesValues[i];
			if ("1".equals(note)) {
				has1 = true;
			}
		}

		System.out.println(has1 ? "-1" : "1");
	}

	public static void main(String[] args) {
		BankNotes notes = new BankNotes();
		notes.run();
		notes.close();
	}

	private Scanner sc;

	private BankNotes() {
		this.sc = new Scanner(System.in);
	}

	private String readLine() {
		if (sc.hasNextLine()) {
			return (sc.nextLine());
		} else {
			return null;
		}
	}

	private void close() {
		try {
			sc.close();
		} catch (Exception e) {
			//log
		}
	}
}


import java.util.Scanner;
public class a {
  static Scanner in=new Scanner(System.in);
  public static void main(String[] args) {
    int n=in.nextInt();
    int c=0;
    for(int i=0;i<n;i++)
      if(in.nextInt()==1)
      c++;
    System.out.println(c==0?1:-1);
  }
}


import java.util.Scanner;

/**
 ** Created by Alik on 11/9/2015.
 */
public class Problem_560A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();
        int temp;
        boolean result = false;
        for (int i = 0; i < number; i++){
            temp = in.nextInt();
            if (temp == 1)
                result = true;
        }
        if (result)
            System.out.print(-1);
        else
            System.out.print(1);
    }
}


import java.util.Scanner;
import java.util.Set;

public class JavaApplication122 {

    public static void main(String[] args) {
        Scanner sin = new Scanner(System.in);
        int x = sin.nextInt();
        boolean b = true;

        for(int i = 0; i < x; i++)
            if(sin.nextInt() == 1)
                b = false;
        if(b)
            System.out.println(-1);
        else
            System.out.println(1);
    }
}


import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class JavaApplication122 {

    static int arr[];
    static int dp[];
    public static void main(String[] args) {
        Scanner sin = new Scanner(System.in);
        int x = sin.nextInt();
        boolean b = true;

        for(int i = 0; i < x; i++)
            if(sin.nextInt() == 1)
                b = false;
        if(b)
            System.out.println(1);
        else
            System.out.println(-1);
    }
}

 class $R {
        InputStream in; byte b; byte[] buf; int bi, bz;
        $R(InputStream I) { in=I; buf=new byte[65536]; bi=bz=0; read(); }
        boolean hasNext() { skip(); return b >= 0; }
        void skip() { while (b >= 0 && b <= 32) read(); }
        String next() {
            StringBuilder sb = new StringBuilder();
            for (skip(); b > 32; read()) sb.append((char)b);
            return sb.length() == 0 ? null : sb.toString(); }
        String nextLine() {
            StringBuilder sb = new StringBuilder();
            for (; b != 10 && b != 13; read()) sb.append((char)b);
            while (b == 10 || b == 13) read();
            return sb.toString(); }
        int nextInt() {
            int ival = 0; boolean isgn = false;
            skip(); if (b == '-') { isgn = true; read(); }
            for (; b > 32; read()) ival = ival*10 + b-48;
            return isgn ? -ival : ival; }
        void read() {
            if (bi==bz) {
                bi=0; try { bz=in.read(buf); } catch(Exception e) { bz=-1; } }
            b = bz == -1 ? -1 : buf[bi++];  }
    }


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int number=scan.nextInt();
		int[] array=new int[number];
		for (int i = 0; i < array.length; i++) {
			array[i]=scan.nextInt();

		}
		if(array[0]==1){
			System.out.println("-1");
		}
		else{
			System.out.println("1");
		}
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int number=scan.nextInt();
		int[] array=new int[number];
		for (int i = 0; i < array.length; i++) {
			array[i]=scan.nextInt();

		}
		Arrays.sort(array);
		if(array[0]==1){
			System.out.println("-1");
		}
		else{
			System.out.println("1");
		}
	}
}


import java.util.Scanner;
public class Code3131 {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int max=0,min=0,res=-1;
        boolean f=false;
        int[] m = new int[n];
        for(int i=0;i<n;i++){
            m[i]=sc.nextInt();
            if(m[i]==1){
                f=true;
                break;
            }
        }
        if(f)System.out.println(-1);
        else System.out.println(1);
    }
}


import java.util.Scanner;
public class Code3131 {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int max=0,min=0,res=-1;
        boolean f=true;
        int[] m = new int[n];
        for(int i=0;i<n;i++){
            m[i]=sc.nextInt();
            if(m[i]==1){
                f=true;
                break;
            }
        }
        if(f)System.out.println(-1);
        else System.out.println(1);
    }
}


import java.util.Scanner;
public class A560 {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int n= in.nextInt(), p = 1;
        for(int i = 0; i<n;i++){
            if(in.nextInt()==1){
                p = -1;
                break;
            }
        }
        System.out.println(p);
    }

}


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

public class tmp {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int num = 1;
        for(int i=0; i<n; i++)
            if(scan.nextInt() == 1)
                num = -1;

        System.out.println(num);

    }

}


import java.util.Scanner;

public class Main560A {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean hasOne = false;
        int n= scanner.nextInt();
        for (int i = 0;!hasOne&&i<n;i++){
            if (scanner.nextInt()==1)
                hasOne = true;
        }
        System.out.println(hasOne?-1:1);
    }

}


import java.util.Scanner;

public class Main560A {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean hasOne = false;
        for (int i = 0;!hasOne&&i<5;i++){
            if (scanner.nextInt()==1)
                hasOne = true;
        }
        System.out.println(hasOne?-1:1);
    }

}


import java.io.*;
import java.util.*;

public class A {
	public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer line = new StringTokenizer(input.readLine());

		int n = Integer.parseInt(line.nextToken());

		line = new StringTokenizer(input.readLine());
		boolean containsOne = false;

		for (int i = 0; i < n; i++) {
			if (1 == Integer.parseInt(line.nextToken())) {
				containsOne = true;
				break;
			}
		}

		System.out.println(containsOne ? -1 : 1);
	}
}


import java.lang.*;
import static java.util.Arrays.sort;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author Mido
 */
public class Test {

    /**
     * @param args the command
     */
    public static void main(String[] args)
    {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),ans=1,x;
		for(int i=1;i<=n;i++)
		{
			x=sc.nextInt();
			if(x==1)ans=-1;
		}
		System.out.println(ans);

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class R313A {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int min = Integer.MAX_VALUE;
		while (n-- > 0) {
			int a = in.nextInt();
			if ( a < min)
				min = a;
		}
		out.println((min == 1)?-1:1);
		out.flush();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CurrencySystemInGeraldion {

	public static void main(String[] args) {
		MyScanner scan = new MyScanner();
		int T = scan.nextInt();

		boolean one = false;
		int i=0;
		while(!one && i<T){
			if(scan.nextInt()==1){
				one=true;
			}
			i++;
		}
		System.out.println(one?"-1":"1");
	}

	//-----------MyScanner class for faster input----------
	   public static class MyScanner {
	      BufferedReader br;
	      StringTokenizer st;

	      public MyScanner() {
	         br = new BufferedReader(new InputStreamReader(System.in));
	      }

	      String next() {
	          while (st == null || !st.hasMoreElements()) {
	              try {
	                  st = new StringTokenizer(br.readLine());
	              } catch (IOException e) {
	                  e.printStackTrace();
	              }
	          }
	          return st.nextToken();
	      }

	      int nextInt() {
	          return Integer.parseInt(next());
	      }

	      long nextLong() {
	          return Long.parseLong(next());
	      }

	      double nextDouble() {
	          return Double.parseDouble(next());
	      }

	      String nextLine(){
	          String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	      }

	   }
	   //--------------------------------------------------------
}


import java.io.*;
import java.util.*;
public final class currency_system
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();
		int ans=1;
		for(int i=0;i<n;i++)
		{
			int x=sc.nextInt();
			if(x==1)
			{
				ans=-1;
				break;
			}
		}
		out.println(ans);
		out.close();
	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		input.nextLine();
		input.nextLine();
		System.out.println(-1);
	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int numOfNumbers = input.nextInt();
		for (int i = 0; i < numOfNumbers; i++) {

			if (input.nextInt() == 1) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(1);
	}
}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();

		boolean negOne = false;

		String[] integersInString = line.split(" ");
		int a[] = new int[integersInString.length];

		for (int i = 0; i < integersInString.length; i++) {
		    a[i] = Integer.parseInt(integersInString[i]);
		    if(a[i] == 1){
		    	negOne = true;
		    	break;
		    }
		}

		if(negOne == true){
			System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int x = 0; x < numberOfValues; x++){
			if(line.charAt(x) != ' '){

				if(x == 0){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x+1) == ' '){
						negOne = true;
						break;
					}
				}
				else if(x == numberOfValues - 1){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' '){
						negOne = true;
						break;
					}
				}
				else{
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' ' && line.charAt(x+1) == ' '){
						negOne = true;
						break;
					}
				}
			}
		}

		if(negOne == true){
			System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int i = 0; i < numberOfValues; i++){
			if((int)line.charAt(i) == 1){
				negOne = true;
				break;
			}
		}

		if(negOne == true){
			 System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int x = 0; x < numberOfValues; x++){
			if(line.charAt(x) != ' '){

				if(x == 0){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x+1) == ' '){
						negOne = true;
					}
				}
				else if(x == numberOfValues - 1){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' '){
						negOne = true;
					}
				}
				else{
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' ' && line.charAt(x+1) == ' '){
						negOne = true;
					}
				}
			}
		}

		if(negOne == true){
			System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int x = 0; x < numberOfValues; x++){
			if(line.charAt(x) != ' '){
				System.out.println("here");
				if(x == 0){
					System.out.println("lpdk");
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x+1) == ' '){
						negOne = true;
						System.out.println("true");
					}
				}
				else if(x == numberOfValues - 1){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' '){
						System.out.println("true");
						negOne = true;
					}
				}
				else{
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' ' && line.charAt(x+1) == ' '){
						System.out.println("true");
						negOne = true;
					}
				}
			}
		}

		if(negOne == true){
			System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int i = 0; i < numberOfValues; i++){
			if(line.charAt(i) == ' '){
				negOne = false;
			}
			else if((int)line.charAt(i) == 1){
				negOne = true;
				break;
			}
		}

		if(negOne == true){
			 System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int x = 0; x < numberOfValues; x++){
			if(line.charAt(x) != ' '){

				if(x == 0){
					System.out.println("lpdk");
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x+1) == ' '){
						negOne = true;
					}
				}
				else if(x == numberOfValues - 1){
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' '){
						negOne = true;
					}
				}
				else{
					if(Character.getNumericValue(line.charAt(x)) == 1 && line.charAt(x-1) == ' ' && line.charAt(x+1) == ' '){
						negOne = true;
					}
				}
			}
		}

		if(negOne == true){
			System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.util.Scanner;
import java.util.*;

public class Geraldion {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String extraInfo = input.nextLine();
		String line = input.nextLine();
		int numberOfValues = line.length();
		boolean negOne = false;

		for(int i = 0; i < numberOfValues; i++){
			if(line.charAt(i) == ' '){
				negOne = false;
			}
			else if((int)line.charAt(i) == 1){
				negOne = true;
				break;
			}

		}

		if(negOne == true){
			 System.out.println(-1);
		}
		else{
			System.out.println(1);
		}

	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author George Marcus
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            if (A[0] == 1) {
                out.println(-1);
                return;
            }
            out.println(1);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author George Marcus
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            Arrays.sort(A);
            if (A[0] == 1) {
                out.println(-1);
                return;
            }
            out.println(1);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class problem1 {

public static void main(String[] args) throws IOException {
	BufferedReader bf = new BufferedReader(new InputStreamReader (System.in)) ;
	bf.readLine() ;
	String n [] = bf.readLine().split(" ") ;
	for (int i = 0; i < n.length; i++) {
		if (n[i]=="1") {
			System.out.println(-1);
			return ;
		}
	}
	System.out.println(1);
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class problem1 {

public static void main(String[] args) throws IOException {
	BufferedReader bf = new BufferedReader(new InputStreamReader (System.in)) ;
	bf.readLine() ;
	boolean b = false ;
	String n [] = bf.readLine().split(" ") ;
	for (int i = 0; i < n.length; i++) {
		if (n[i].equals("1")) {
		b=true ;
		}
	}
	if (!b) {
		System.out.println(1);
	}
	else
		System.out.println(-1);

}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class problem1 {

public static void main(String[] args) throws IOException {
	BufferedReader bf = new BufferedReader(new InputStreamReader (System.in)) ;
	bf.readLine() ;
	boolean b = false ;
	String n [] = bf.readLine().split(" ") ;
	for (int i = 0; i < n.length; i++) {
		if (n[i]!="1") {
		b=true ;
		}
	}
	if (b) {
		System.out.println(1);
	}
	else
		System.out.println(-1);

}
}


import java.util.Scanner;
public class UNfortuanteSum {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();

		int m[]=new int[n];

		int count=0;
		int sum=0;
		for(int i=0; i<n; i++){
			m[i]=input.nextInt();
			sum=sum+m[i];
			if(m[i]==1){
				count++;
			}

		}
		if(count>=1){
		System.out.println("-1");
		}
		else
			System.out.println(sum+1);

	}

}


import java.util.Scanner;
public class UNfortuanteSum {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();

		int m[]=new int[n];

		int count=0;
		int sum=0;
		for(int i=0; i<n; i++){
			m[i]=input.nextInt();
			sum=sum+m[i];
			if(m[i]==1){
				count++;
			}

		}
		if(count>=1){
		System.out.println("-1");
		}
		else
			System.out.println(1);

	}

}


import java.util.Scanner;
public class UNfortuanteSum {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();

		int m[]=new int[n];

		int count=0;
		int sum=0;
		for(int i=0; i<n; i++){
			m[i]=input.nextInt();
			sum=sum+i;
			if(m[i]==1){
				count++;
			}

		}
		if(count>=1){
			System.out.println("-1");
		}
		else
			System.out.println(sum+1);

	}

}


import java.util.HashSet;
import java.util.Scanner;

public class A {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        HashSet<Integer> set = new HashSet<Integer>();

        for (int i = 0; i < n; i++){
            set.add(scan.nextInt());
        }

        if (set.contains(1)){
            System.out.println(-1);
        } else {
            System.out.println(1);
        }
    }

}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{

	public static void main(String[] args) throws IOException
	{
		Main main = new Main();
		main.read();
	}

	/* IO */
	private InputReader in;
	private StringBuilder ans;

	/* fields */
	int n;
	int arr[];

	private void read() throws IOException
	{

		// streams
		boolean file = false;
		if (file)
			in = new InputReader(new FileInputStream("input.txt"));
		else
			in = new InputReader(System.in);
		ans = new StringBuilder();

		// read
		n = Integer.parseInt(in.next());
		for (int i = 0; i < n; i++)
			arr[i] = Integer.parseInt(in.next());

		System.out.println(solve());

	}

	private int solve()
	{
		for (int x : arr)
			if (x == 1)
				return -1;
		return 1;

	}

}

class InputReader
{
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream)
	{
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next()
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			try
			{
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e)
			{
				throw new RuntimeException(e);
			}
		return tokenizer.nextToken();
	}

}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{

	public static void main(String[] args) throws IOException
	{
		Main main = new Main();
		main.read();
	}

	/* IO */
	private InputReader in;
	private StringBuilder ans;

	/* fields */
	int n;
	int arr[];

	private void read() throws IOException
	{

		// streams
		boolean file = false;
		if (file)
			in = new InputReader(new FileInputStream("input.txt"));
		else
			in = new InputReader(System.in);
		ans = new StringBuilder();

		// read
		n = Integer.parseInt(in.next());
		arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = Integer.parseInt(in.next());

		System.out.println(solve());

	}

	private int solve()
	{
		for (int x : arr)
			if (x == 1)
				return -1;
		return 1;

	}

}

class InputReader
{
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream)
	{
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next()
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			try
			{
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e)
			{
				throw new RuntimeException(e);
			}
		return tokenizer.nextToken();
	}

}