#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2)
    for(int i=1;i<=n;i++)  {if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    else
    for(int i=1;i<=n;i++)  {if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    cout<<ans.size()<<"\n";
    for(auto i : ans)   cout<<i<<" ";
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void dfs(ll s)
{
    vis[s] = true;
    for(auto u : v[s])
    {
        if(!vis[u])
        {
           l[u]=l[s]+1;
           dfs(u);
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    cout<<min((ll)ans.size(),n/2)<<"\n";
    for(int i=0;i<min((ll)ans.size(),n/2);i++)  cout<<ans[i]<<" ";
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void dfs(ll s)
{
    vis[s] = true;
    for(auto u : v[s])
    {
        if(!vis[u])
        {
           l[u]=l[s]+1;
           dfs(u);
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2)
    for(int i=1;i<=n;i++)  {if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    else
    for(int i=1;i<=n;i++)  {if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void dfs(ll s)
{
    vis[s] = true;
    for(auto u : v[s])
    {
        if(!vis[u])
        {
           l[u]=l[s]+1;
           dfs(u);
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    vll ans,ans1;
    for(int i=1;i<=n;i++)
    if(l[i]%2==1)   ans.pb(i);
    else ans1.pb(i);
    if(ans1.size()<=ans.size())   for(auto i : ans1)  cout<<i<<" ";
    else  for(auto i : ans) cout<<i<<" ";
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    //l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2)
    for(int i=1;i<=n;i++)  {if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    else
    for(int i=1;i<=n;i++)  {if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m;
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0,vis[i]=false;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    //cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2){
        cout<<ans.size()<<"\n";
        for(int i=1;i<=n;i++){
            if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";
        }
    }
    else{
        cout<<n-ans.size()<<"\n";
        for(int i=1;i<=n;i++){
            if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";
        }
    }
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    //cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2){
        cout<<ans.size()<<"\n";
        for(int i=1;i<=n;i++){
            if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";
        }
    }
    else{
        cout<<n-ans.size()<<"\n";
        for(int i=1;i<=n;i++){
            if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";
        }
    }
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    cout<<min((ll)ans.size(),n/2)<<"\n";
    if(ans.size()<=n/2)
    for(int i=1;i<=n;i++)  {if(binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    else
    for(int i=1;i<=n;i++)  {if(!binary_search(ans.begin(),ans.end(),i)) cout<<i<<" ";}
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll              long long
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll             vector<ll>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define md              1e9 +7
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define f(i,j,n)        for(ll i=j;i<n;i++)
#define r(i,j,n)        for(ll i=n-1;i>=j;i--)
vll v[1000000];
ll l[1000000]={0}; // level
bool vis[1000000];//make it false
void bfs(ll root) {
    queue <ll> q;
    q.push(root);
    l[ root ] = 0 ;
    vis[ root ] = true;
    while(!q.empty())
    {
        ll s = q.front();
        q.pop();
        for(auto u : v[ s ])
        {
            if(!vis[ u ])
            {
                l[ u ] = l[ s ]+1;
                q.push(u);
                vis[ u] = true;
            }
        }
    }
}
void solve()
{
    ll n,m;cin>>n>>m; memset(vis,false,sizeof(vis)); //vll v[n+5];
    for(int i=0;i<n+10;i++) v[i].clear(),l[i]=0;
    for(int i=0;i<m;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    vll ans;
    for(int i=1;i<=n;i++)   if(l[i]%2==1)   ans.pb(i);
    sort(ans.begin(),ans.end());
    for(auto i : ans)   cout<<i<<" ";
    cout<<"\n";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
    #endif
    ll test_cases=1; cin>>test_cases;
    for(ll t=1;t<=test_cases;t++)
        solve();
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;map<int ,vector<int>>v;vis.assign(200001,0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }vector<int>ans;

 for(auto it=v.begin();it!=v.end();it++)
 {
 	if(vis[it->first]==0&&it->second.size()>=1)
 	{
 	vis[it->first]=1;ans.pb(it->first);
 	for(int j=0;j<it->second.size();j++)
 	{
 		vis[it->second[j]]=1;
 	}
 	}
 }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;vector<vector<int>>v(200001);vis.assign(200001,0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }vector<int>ans;
  for(int i=1;i<=n;i++)
  {
  	if(v[i].size()>=1&&vis[i]==0)
  	{
  		vis[i]=1;ans.pb(i);
  		for(int j=0;j<v[i].size();j++)
  		{
  			vis[v[i][j]]=1;
  		}
  	}
  }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;map<int ,vector<int>>v;vis.assign(200001,0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }vector<int>ans;

 for(auto it=v.begin();it!=v.end();it++)
 {
 	if(vis[it->first]==1)continue;
 	vis[it->first]=1;ans.pb(it->first);
 	for(int j=0;j<it->second.size();j++)
 	{
 		vis[it->second[j]]=1;
 	}
 }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);vector<vector<int>>v(200001);vector<int>ans;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c%2==0)
 	{
 		ans.pb(root);
 	}
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c+1);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }
  int c=1;
  dfs(1,c);

  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;ans.clear();
 vis.assign(200001,0);
 for(int i=0;i<200001;i++)v[i].clear();

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis;vector<vector<int>>v;vector<int>ans,ans2;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c==0)
 	{
 		ans.pb(root);
 	}
 	else ans2.pb(root);
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],1-c);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  vector<bool>vi(n+1,0);
  vis=vi;v.resize(n+1);
  vector<int>xx,yy;ans=xx,ans2=yy;

  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }

  dfs(1,0);
  if(ans.size()<ans2.size())
  {
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
  }
  else
  {
      cout<<ans2.size()<<endl;
      for(int i=0;i<ans2.size();i++)cout<<ans2[i]<<" ";cout<<endl;
  }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);vector<vector<int>>v(200001);vector<int>ans;
 int dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c%2==0)
 	{
 		ans.pb(root);
 	}
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c+1);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }
  int c=0;
  dfs(1,c);

  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;ans.clear();
 vis.assign(200001,0);
 for(int i=0;i<200001;i++)v[i].clear();
 v.resize(200001);

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);vector<vector<int>>v(200001);vector<int>ans;
 int dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c%2==0)
 	{
 		ans.pb(root);
 	}
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c+1);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;vis.assign(n+1,0);v.resize(n+1);
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }
  int c=0;
  dfs(1,c);

  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;ans.clear();

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis;vector<vector<int>>v;vector<int>ans,ans2;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c%2==0)
 	{
 		ans.pb(root);
 	}
 	else ans2.pb(root);
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c+1);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;vis.assign(n+1,0);v.resize(n+1);

  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }

  dfs(1,0);
  if(ans.size()<ans2.size())
  {
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
  }
  else
  {
      cout<<ans2.size()<<endl;
      for(int i=0;i<ans2.size();i++)cout<<ans2[i]<<" ";cout<<endl;
  }

ans.clear();ans2.clear();

  }

}


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

#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<int>vis;vector<vector<int>>v,u;vector<int>ans,ans2;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c==0)
 	{
 		ans.pb(root);
 	}
 	else ans2.pb(root);
 	c=1-c;
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c);
 		}
 	}
 }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  vector<int>vi(n+1,0);v=u;
  vis=vi;v.resize(n+1);
  vector<int>xx,yy;ans=xx,ans2=yy;

  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }

  dfs(1,0);
  if(ans.size()<ans2.size())
  {
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
  }
  else
  {
      cout<<ans2.size()<<endl;
      for(int i=0;i<ans2.size();i++)cout<<ans2[i]<<" ";cout<<endl;
  }

  }

}


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

#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<int>vis;vector<vector<int>>v;vector<int>ans,ans2;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c==0)
 	{
 		ans.pb(root);
 	}
 	else ans2.pb(root);
 	c=1-c;
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],c);
 		}
 	}
 }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  vector<int>vi(n+1,0);
  vis=vi;v.resize(n+1);
  vector<int>xx,yy;ans=xx,ans2=yy;

  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }

  dfs(1,0);
  if(ans.size()<ans2.size())
  {
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
  }
  else
  {
      cout<<ans2.size()<<endl;
      for(int i=0;i<ans2.size();i++)cout<<ans2[i]<<" ";cout<<endl;
  }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis(200001,0);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;map<int ,vector<int>>v;vis.assign(200001,0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }vector<int>ans;

 for(auto it=v.begin();it!=v.end();it++)
 {
 	if(vis[it->first]==0&&it->second.size()>=2)
 	{
 	vis[it->first]=1;ans.pb(it->first);
 	for(int j=0;j<it->second.size();j++)
 	{
 		vis[it->second[j]]=1;
 	}
 	}
 }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;

  }

}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define endl '\n'
 vector<bool>vis;vector<vector<int>>v;vector<int>ans,ans2;
 void dfs(int root,int c)
 {

 	vis[root]=1;
 	if(c==0)
 	{
 		ans.pb(root);
 	}
 	else ans2.pb(root);
 	for(int i=0;i<v[root].size();i++)
 	{
 		if(vis[v[root][i]]==0)
 		{
 			dfs(v[root][i],1-c);
 		}
 	}
 }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int t;cin>>t;
  while(t--)
  {
  	int n,m;
  cin>>n>>m;
  vector<bool>vi(n+1,0);
  vis=vi;v.resize(n+1);

  for(int i=0;i<m;i++)
  {
  	int x,y;cin>>x>>y;
  	v[x].pb(y);
  	v[y].pb(x);
  }

  dfs(1,0);
  if(ans.size()<ans2.size())
  {
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
  }
  else
  {
      cout<<ans2.size()<<endl;
      for(int i=0;i<ans2.size();i++)cout<<ans2[i]<<" ";cout<<endl;
  }

ans.clear();ans2.clear();

  }

}


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

int v [200005];
int vis[200005];
vector<int> adj[200005];
vector <int> ans;

void dfs(int node ){
    int killed = 0;
    vis[node]=1;
    for(int i : adj[node]){
        if(v[i])killed++;
    }
    if(adj[node].size() > killed){
        ans.push_back(node);
        v[node] = 1;
        for(int i : adj[node])v[i]=1;
    }
    for(int i : adj[node]){
        if(vis[i])continue;
        dfs(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
            vis[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int start ;
        int best = 0;
        for(int i = 1 ; i <= n ; i++){
            if(adj[i].size() >  best){
                best = adj[i].size();
                start = i;
            }
        }
        dfs(start);
        for(int i = 1 ; i <= n ; i ++){
            if(!v[i])ans.push_back(i);
        }
        cout << ans.size() <<endl;
        for(int i = 0 ; i < ans.size() ;i ++)cout<<ans[i]<< " ";
        cout<<endl;
    }

    return 0;
}


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

vector<int> adj[200005];
vector<int> tree[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

void dfs(int node){
    v[node] =1;
    for(int i : adj[node]){
        if(v[i])continue;
        tree[node].push_back(i);
        tree[i].push_back(node);
        dfs(i);
    }
}
void dfs2(int node , int prev ){
    int kill = 0 ;
    for(int i : tree[node]){
        if(v[i])kill++;
    }
    if(tree[node].size() > kill){
        v[node] = 1;
        for(int i : tree[node]){
            v[i] = 1;
        }
    }
    for(int i : tree[node]){
        if(i == prev )continue;
        dfs2(i,node);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            tree[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1);
        for(int i = 1 ; i <= n ; i++){
            if(tree[i].size()!=1){
                dfs2(i,i);
                break;
            }
        }
        //
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];
int minu[200005];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i++){
            degree[i] = { adj[i].size() , i };
        }

        sort(degree+1,degree+n+1,greater<pair<int,int>>());

        for(int i = 1 ; i <= n ; i ++){
            if(v[ degree[i].second ] || (degree[i].first - minu[degree[i].second] == 0 ) )continue;
            int node = degree[i].second;
            ans.push_back(node);
            v[node] = 1;
            for(int j : adj[node]){
                v[j] = 1 ;
                minu[j] ++;
            }
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            if(v[i])continue;
            int killed = 0;
            for(int j : adj[i]){
                if(v[j])killed++;
            }
            if(killed == adj[i].size())continue;
            v[i] = 1;
            ans.push_back(i);
            for(int j : adj[i])v[j]=1;
        }

        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            if(v[i])continue;
            int killed = 0;
            for(int j : adj[i]){
                if(v[j])killed++;
            }
            if(killed == adj[i].size())continue;
            v[i] = 1;
            ans.push_back(i);
            for(int j : adj[i])v[j]=1;
        }
        if(ans.size() > n/2)return -1;
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            degree[i] = {adj[i].size() , i };
        }
        sort(degree+1,degree+n+1,greater<pair<int,int>>());
        for(int i = 1 ; i <= n ; i ++){
            int node = degree[i].second;
            if(v[node])continue;
            int killed = 0;
            for(int j : adj[node]){
                if(v[j])killed++;
            }
            if(killed == adj[node].size())continue;
            v[node] = 1;
            ans.push_back(node);
            for(int j : adj[node])v[j]=1;
        }
        for(int i = 1 ; i <= n ; i++){
            if(v[i])continue;
            ans.push_back(i);
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            int killed = 0;
            for(int j : adj[i]){
                if(v[j])killed++;
            }
            if(killed == adj[i].size())continue;
            v[i] = 1;
            ans.push_back(i);
            for(int j : adj[i])v[j]=1;
        }

        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans1;
vector<int>ans2;

void dfs(int node,int dye){
    v[node] = 1;
    for(int i : adj[node]){
        if(v[i])continue;
        dfs(i);
    }
    if(dye)ans1.push_back(node);
    else(dye)ans2.push_back(node);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        ans1.clear();
        ans2.clear();
        dfs(1,dye);
        if(ans1.size()>ans2.size())swap(ans1,ans2);
        cout<<ans1.size()<<endl;
        for(int i = 0 ; i < ans1.size() ; i++)cout<<ans1[i]<<" ";
        cout<<endl;
    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            if(v[i])continue;
            int killed = 0;
            for(int j : adj[i]){
                if(v[j])killed++;
            }
            if(killed == adj[i].size())continue;
            v[i] = 1;
            ans.push_back(i);
            for(int j : adj[i])v[j]=1;
        }
        for(int i = 1 ; i <= n ; i++){
            if(v[i])continue;
            ans.push_back(i);
        }
        if(ans.size() > n/2 + n%2)return -1;
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

int v [200005];
int vis[200005];
vector<int> adj[200005];
vector <int> ans;

void dfs(int node ){
    int killed = 0;
    vis[node]=1;
    for(int i : adj[node]){
        if(v[i])killed++;
    }
    if(adj[node].size() > killed){
        ans.push_back(node);
        v[node] = 1;
        for(int i : adj[node])v[i]=1;
    }
    for(int i : adj[node]){
        if(vis[i])continue;
        dfs(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
            vis[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int start ;
        int best = 0;
        for(int i = 1 ; i <= n ; i++){
            if(adj[i].size() >  best){
                best = adj[i].size();
                start = i;
            }
        }
        dfs(start);
        for(int i = 1 ; i <= n ; i ++){
            if(!v[i])ans.push_back(i);
        }
        if(ans.size> n/2 + n%2)return -1;
        cout << ans.size() <<endl;
        for(int i = 0 ; i < ans.size() ;i ++)cout<<ans[i]<< " ";
        cout<<endl;
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i++){
            degree[i] = { adj[i].size() , i };
        }
        sort(degree+1,degree+n+1,greater<pair<int,int>>());
        for(int i = 1 ; i <= n ; i ++){
            if(v[ degree[i].second ])continue;
            int node = degree[i].second;
            ans.push_back(node);
            v[node] = 1;
            for(int j : adj[node])v[j]=1;
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            if(v[i])continue;
            int killed = 0;
            for(int j : adj[i]){
                if(v[j])killed++;
            }
            if(killed == adj[i].size())continue;
            v[i] = 1;
            ans.push_back(i);
            for(int j : adj[i])v[j]=1;
        }
        for(int i = 1 ; i <= n ; i++){
            if(v[i])continue;
            ans.push_back(i);
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
vector<int> tree[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

void dfs(int node){
    v[node] =1;
    for(int i : adj[node]){
        if(v[i])continue;
        tree[node].push_back(i);
        tree[i].push_back(node);
        dfs(i);
    }
}
void dfs2(int node , int prev ,bool dye){
    if(dye){
        ans.push_back(node);
    }
    for(int i : tree[node]){
        if(i == prev)continue;
        dfs2(i,node,!dye);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            tree[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1);
        for(int i = 1 ; i <= n ; i++){
            if(tree[i].size()!=1){
                dfs2(i,i,1);
                break;
            }
        }
        if(ans.size() > n/2 + n%2)return -1;
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i++){
            degree[i] = { adj[i].size() , i };
        }
        sort(degree+1,degree+n+1,greater<pair<int,int>>());
        for(int i = 1 ; i <= n ; i ++){
            if(v[ degree[i].second ])continue;
            int node = degree[i].second;
            ans.push_back(node);
            v[node] = 1;
            for(int j : adj[node])v[j]=1;
        }
        if(ans.size()>n/2)return -1;
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];
int minu[200005];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
            minu[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i++){
            degree[i] = { adj[i].size() , i };
        }

        for(int i = 1 ; i <= n ; i ++){
            if(v[ degree[i].second ] || (degree[i].first - minu[degree[i].second] == 0 ) )continue;
            int node = degree[i].second;
            ans.push_back(node);
            v[node] = 1;
            for(int j : adj[node]){
                v[j] = 1 ;
                minu[j] ++;
            }
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

int vis[200005];
vector<int> adj[200005];
vector <int> ans;
vector <int> ans2;

void dfs(int node ,int dye ){
    vis[node] = 1;
    if(dye)ans.push_back(node);
    for(int i : adj[node]){
        if(vis[i])continue;
        dfs(i,!dye);
    }
}
void dfs2(int node ,int dye ){
    vis[node]= 1;
    if(dye)ans2.push_back(node);
    for(int i : adj[node]){
        if(vis[i])continue;
        dfs2(i,!dye);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        ans2.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            vis[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1,1);
        for(int i = 1 ; i <= n ; i ++)vis[i]=0;
        dfs2(adj[1][0],1);
        if(ans.size() > ans2.size())swap(ans,ans2);
        cout<<ans.size()<<endl;
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<< " ";
        cout << endl;
    }

    return 0;
}


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

int v [200005];
int vis[200005];
vector<int> adj[200005];
vector <int> ans;

void dfs(int node ){
    int killed = 0;
    vis[node]=1;
    for(int i : adj[node]){
        if(v[i])killed++;
    }
    if(adj[node].size() > killed){
        ans.push_back(node);
        v[node] = 1;
        for(int i : adj[node])v[i]=1;
    }
    for(int i : adj[node]){
        if(vis[i])continue;
        dfs(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
            vis[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int start ;
        int best = 0;
        for(int i = 1 ; i <= n ; i++){
            if(adj[i].size() >  best){
                best = adj[i].size();
                start = i;
            }
        }
        for(int i = 1 ; i <= n ; i ++){
            if(!v[i])ans.push_back(i);
        }
        dfs(start);
        if(ans.size() > n/2 + n%2)return -1;
        cout << ans.size() <<endl;
        for(int i = 0 ; i < ans.size() ;i ++)cout<<ans[i]<< " ";
        cout<<endl;
    }

    return 0;
}


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

int vis[200005];
vector<int> adj[200005];
vector <int> ans;
vector <int> ans2;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        ans2.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            vis[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        vector <pair<int,int>> q;
        vis[1]=1;
        q.push_back({1,1});
        for(int i = 0 ; i < q.size() ; i++){
            int node = q[i].first;
            int dye = q[i].second;
            if(dye == 1)ans.push_back(node);
            for(int i : adj[ node ]){
                if(vis[i])continue;
                vis[i]=1;
                q.push_back({i,!dye});
            }
        }
        q.clear();
        for(int i = 1 ; i <= n ; i ++)vis[i]=0;
        q.push_back({adj[1][0],1});
        vis[ adj[1][0] ] = 1;
        for(int i = 0 ; i < q.size() ; i++){
            int node = q[i].first;
            int dye = q[i].second;
            if(dye == 1)ans2.push_back(node);
            for(int i : adj[ node ]){
                if(vis[i])continue;
                vis[i]=1;
                q.push_back({i,!dye});
            }
        }

        if(ans.size() > ans2.size())swap(ans,ans2);
        cout<<ans.size()<<endl;
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<< " ";
        cout << endl;
    }

    return 0;
}


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

vector<int> adj[200005];
vector<int> tree[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

void dfs(int node){
    v[node] =1;
    for(int i : adj[node]){
        if(v[i])continue;
        tree[node].push_back(i);
        tree[i].push_back(node);
        dfs(i);
    }
}
void dfs2(int node , int prev ){
    int kill = 0 ;
    for(int i : tree[node]){
        if(v[i])kill++;
    }
    if(tree[node].size() > kill){
        v[node] = 1;
        ans.push_back(node);
        for(int i : tree[node]){
            v[i] = 1;
        }
    }
    for(int i : tree[node]){
        if(i == prev )continue;
        dfs2(i,node);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            tree[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1);
        for(int i = 1 ; i <= n ; i++){
            if(tree[i].size()!=1){
                dfs2(i,i);
                break;
            }
        }
        //
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans1;
vector<int>ans2;

void dfs(int node,int dye){
    v[node] = 1;
    for(int i : adj[node]){
        if(v[i])continue;
        dfs(i,!dye);
    }
    if(dye)ans1.push_back(node);
    else ans2.push_back(node);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n,m;
        cin >> n >> m;
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        ans1.clear();
        ans2.clear();
        dfs(1,1);
        if(ans1.size()>ans2.size())swap(ans1,ans2);
        cout<<ans1.size()<<endl;
        for(int i = 0 ; i < ans1.size() ; i++)cout<<ans1[i]<<" ";
        cout<<endl;
    }
    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans1;
vector<int>ans2;

void dfs(int node,int dye){
    v[node] = 1;
    for(int i : adj[node]){
        if(v[i])continue;
        dfs(i,!dye);
    }
    if(dye)ans1.push_back(node);
    else ans2.push_back(node);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <=n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        ans1.clear();
        ans2.clear();
        dfs(1,1);
        if(ans1.size()>ans2.size())swap(ans1,ans2);
        cout<<ans1.size()<<endl;
        for(int i = 0 ; i < ans1.size() ; i++)cout<<ans1[i]<<" ";
        cout<<endl;
    }
    return 0;
}


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

vector<int> adj[200005];
vector<int> tree[200005];
int v [200005];
vector<int>ans;
pair<int,int> degree [200005];

void dfs(int node){
    v[node] =1;
    for(int i : adj[node]){
        if(v[i])continue;
        tree[node].push_back(i);
        tree[i].push_back(node);
        dfs(i);
    }
}
void dfs2(int node , int prev ,bool dye){
    if(dye){
        ans.push_back(node);
    }
    for(int i : tree[node]){
        if(i == prev)continue;
        dfs2(i,node,!dye);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            tree[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1);
        for(int i = 1 ; i <= n ; i++){
            if(tree[i].size()!=1){
                dfs2(i,i,1);
                break;
            }
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
vector<int> tree[200005];
int v [200005];
vector<int>ans;

void dfs(int node){
    v[node] =1;
    for(int i : adj[node]){
        if(v[i])continue;
        tree[node].push_back(i);
        tree[i].push_back(node);
        dfs(i);
    }
}
void dfs2(int node , int prev ){
    int kill = 0 ;
    for(int i : tree[node]){
        if(v[i])kill++;
    }
    if(tree[node].size() > kill){
        v[node] = 1;
        ans.push_back(node);
        for(int i : tree[node]){
            v[i] = 1;
        }
    }
    for(int i : tree[node]){
        if(i == prev )continue;
        dfs2(i,node);
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            tree[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1);
        for(int i = 1 ; i <= n ; i++)v[i]=0;
        for(int i = 1 ; i <= n ; i++){
            if(tree[i].size()!=1){
                dfs2(i,i);
                break;
            }
        }
        for(int i = 1 ; i <= n ; i ++){
            if(!v[i])ans.push_back(i);
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


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

vector<int> adj[200005];
int v [200005];
vector<int>ans;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        ans.clear();
        int n,m;
        cin >> n >> m;
        for(int i = 1 ; i <= n ; i ++){
            adj[i].clear();
            v[i] = 0;
        }
        for(int i = 0 ; i < m ; i ++){
            int u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        for(int i = 1 ; i <= n ; i ++){
            if(v[i])continue;
            ans.push_back(i);
            v[i] = 1;
            for(int j : adj[i])v[j]=1;
        }
        cout << ans.size()<<'\n';
        for(int i = 0 ; i < ans.size() ; i++)cout<<ans[i]<<" ";
        cout<<'\n';
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
int tl=1;
void dfs(int u,bool flag)
{
	ans[u]=flag;
	f[u]=1-tl;
	for(auto i:adj[u])
	{
		if(f[i]==tl)dfs(i,1-flag);
		}
	}

void solve()
{
    tl=1-tl;
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
void dfs(int u,bool flag,int tl)
{
	ans[u]=flag;
	f[u]=1-tl;
	for(auto i:adj[u])
	{
		if(f[i]==tl)dfs(i,1-flag,tl);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
int tl=1;
void dfs(int u,bool flag)
{
	ans[u]=tl;
	f[u]=1-tl;
	for(auto i:adj[u])
	{
		if(f[i]==tl)dfs(i,1-flag);
		}
	}

void solve()
{
    tl=1-tl;
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==1-tl)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==tl)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vi adj[N];
bool f[N];
bool ans[N];
void dfs(int u,bool flag)
{
	ans[u]=flag;
	f[u]=true;
	for(auto i:adj[u])
	{
		if(f[i]==false)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)adj[i].clear();
	memset(f,0,sizeof(f));
	memset(ans,0,sizeof(ans));
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
void dfs(int u,bool flag,int tl)
{
	ans[u]=flag;
	f[u]=1-tl;
	for(auto i:adj[u])
	{
		if(f[i]==tl)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
void dfs(int u,bool flag)
{
	ans[u]=flag;
	f[u]=true;
	for(auto i:adj[u])
	{
		if(f[i]==false)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vi ans[2];
vector<vi>adj;
vector<int>f;

void dfs(int u,bool flag)
{
	ans[flag].pb(u+1);
	f[u]=1;
	for(auto i:adj[u])
	{
		if(f[i]==0)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	f.clear();
	f.resize(n);
	ans[0].clear();
	ans[1].clear();
	adj.clear();
	adj.resize(n,vi());

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	if(ans[0].size()<ans[1].size())
	{
		cout<<ans[0].size()<<"\n";
		for(auto i:ans[0])cout<<i<<' ';
		cout<<"\n";
		}
	else{
		cout<<ans[1].size()<<"\n";
		for(auto i:ans[1])cout<<i<<' ';
		cout<<"\n";

		}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<int> ans[2];
vector<vi>adj;
vector<int>f;

void dfs(int u,bool flag)
{
	ans[flag].pb(u+1);
	f[u]=1;
	for(auto i:adj[u])
	{
		if(f[i]==0)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	f.clear();
	f.resize(n);
	ans[0].clear();
	ans[1].clear();
	adj.clear();
	adj.resize(n,vi());

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	if(ans[0].size()<=ans[1].size())
	{
		cout<<ans[0].size()<<"\n";
		for(auto i:ans[0])cout<<i<<' ';
		cout<<"\n";
		}
	else{
		cout<<ans[1].size()<<"\n";
		for(auto i:ans[1])cout<<i<<' ';
		cout<<"\n";

		}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vi adj[N];
bool f[N];
bool ans[N];
void dfs(int u,bool flag)
{
	ans[u]=flag;
	f[u]=true;
	for(auto i:adj[u])
	{
		if(f[i]==false)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> ans;
vector<vi>adj;
vector<int>f;

void dfs(int u,bool flag)
{
	ans[flag].pb(u+1);
	f[u]=1;
	for(auto i:adj[u])
	{
		if(f[i]==0)dfs(i,1-flag);
		}
	}

void solve()
{
	int n,m;
	cin>>n>>m;
	f.clear();
	f.resize(n);
	ans.clear();
	ans.resize(2);
	adj.clear();
	adj.resize(n,vi());

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0);
	if(ans[0].size()<=ans[1].size())
	{
		cout<<ans[0].size()<<"\n";
		for(auto i:ans[0])cout<<i<<' ';
		cout<<"\n";
		}
	else{
		cout<<ans[1].size()<<"\n";
		for(auto i:ans[1])cout<<i<<' ';
		cout<<"\n";

		}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

vector<vi> adj;
bool f[N];
bool ans[N];
int tl=1;
void dfs(int u,bool flag)
{
	ans[u]=flag;
	f[u]=1-tl;
	for(auto i:adj[u])
	{
		if(f[i]==tl)dfs(i,1-flag);
		}
	}

void solve()
{
    tl=1-tl;
	int n,m;
	cin>>n>>m;
	adj.assign(n,vi());
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		}
	dfs(0,0,0);
	vi z;
	for(int i=0;i<n;i++)if(ans[i]==false)z.pb(i+1);
	if(z.size()<=n/2){
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";
}
else
{
z.clear();
	for(int i=0;i<n;i++)if(ans[i]==true)z.pb(i+1);
	cout<<z.size()<<"\n";
	for(auto i:z)cout<<i<<' ';
	cout<<"\n";

	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	cin>>tc;
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;
typedef pair<int, int> ii;

bool ss(ii tr, ii s){return tr.first > s.first;}

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		vector<ii> b;
		for(int i = 1; i <= n; i++) b.push_back(make_pair(adj[i].size(), i));
		sort(b.begin(), b.end(), ss);
		for(auto x: b){
			if(!mark[x.second]){
				ans.push_back(x.second);
				mark[x.second] = true;
				for(auto x: adj[x.second]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;
typedef pair<int, int> ii;

bool ss(ii tr, ii s){return tr.first > s.first};

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		vector<ii> b;
		for(int i = 1; i <= n; i++) b.push_back(make_pair(adj[i].size(), i));
		sort(b.begin(), b.end(), ss);
		for(auto x: b){
			if(!mark[x.first]){
				ans.push_back(x.second);
				mark[x.second] = true;
				for(auto x: adj[x.second]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main1(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		queue<int> q;
		q.push(1);
		int step = 1;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main1(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main1(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		for(int i = 1; i <= n; i++){
			if(!mark[i]){
				ans.push_back(i);
				mark[i] = true;
				for(auto x: adj[i]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main1(){
	ios_base::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		mark[1] = true;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main(){
	ios_base::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, n+5);
		queue<int> q;
		q.push(1);
		int step = 1;
		mark[1] = true;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main(){
	ios_base::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		mark[1] = true;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;
typedef pair<int, int> ii;

bool ss(ii tr, ii s){return tr.first > s.first};

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		vector<ii> b;
		for(int i = 1; i <= n; i++) b.push_back({adj[i].size(), i});
		sort(b.begin(), b.end(), ss);
		for(auto x: b){
			if(!mark[x.first]){
				ans.push_back(x.second);
				mark[x.second] = true;
				for(auto x: adj[x.second]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;
typedef pair<int, int> ii;

bool ss(ii tr, ii s){return tr.first > s.first;}

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		vector<ii> b;
		for(int i = 1; i <= n; i++) b.push_back(make_pair(adj[i].size(), i));
		sort(b.begin(), b.end(), ss);
		for(auto x: b){
			if(!mark[x.second]){
				ans.push_back(x.second);
				mark[x.second] = true;
				for(auto x: adj[x.second]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ansc, ansl;

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		ansc.clear();
		ansl.clear();
		memset(mark, false, N);
		queue<int> q;
		q.push(1);
		int step = 1;
		mark[1] = true;
		while(q.size()){
			for(int sz = q.size(); sz; sz--){
				int tmp = q.front();
				q.pop();
				if(step%2) ansl.push_back(tmp);
				else ansc.push_back(tmp);
				for(auto x: adj[tmp]) if(!mark[x]){
					mark[x] = true;
					q.push(x);
				}
			}
			step++;
		}
		if(ansc.size() < ansl.size()){
			cout << ansc.size() << endl;
			for(auto x: ansc) cout << x << " ";
		}else{
			cout << ansl.size() << endl;
			for(auto x: ansl) cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;
typedef pair<int, int> ii;

bool ss(ii tr, ii s){return tr.first > s.first;}

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		vector<ii> b;
		for(int i = 1; i <= n; i++) b.push_back(make_pair(adj[i].size(), i));
		sort(b.begin(), b.end(), ss);
		for(auto x: b){
			if(!mark[x.first]){
				ans.push_back(x.second);
				mark[x.second] = true;
				for(auto x: adj[x.second]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n, m;
bool mark[N];
vector<vector<int>> adj(N);
vector<int> ans;

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n >> m;
		memset(mark, false, N);
		ans.clear();
		for(int i = 1; i <= n; i++) adj[i].clear();
		for(int i = 1; i <= m; i++){
			int u, v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		for(int i = 1; i <= n; i++){
			if(!mark[i]){
				ans.push_back(i);
				mark[i] = true;
				for(auto x: adj[i]) mark[x] = true;
			}
		}
		cout << ans.size() << endl;
		for(auto x: ans) cout << x << " ";
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<(n%2==0?n/2:n/2+1)<<endl;
    j=n%2==0?n/2:n/2+1;
    for(i=0;i=j;i++)
        cout<<a[i].second<<" ";
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<n/2<<endl;
    j=n/2;
    for(i=0;i<j;i++)
       {

        {
             cout<<a[i].second<<" ";
        }
        //else
          //   cout<<a[j+i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}