#include <bits/stdc++.h>
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define pri(a) printf("%d",a)
#define prn() printf("\n");
#define pb(a) push_back(a)
using namespace std;
const int maxn=200005;

int t,n,m,x,y;
vector<int> p[maxn];
int c[maxn];

void dfs(int i,int color)
{
    if(c[i]==t+1||c[i]==t+1+maxn)
        return;
    c[i]=color;
    for(int j=0;j<p[i].size();++j)
        dfs(p[i][j],2*t+2+maxn-color);
}

void init()
{
    for(int i=1;i<=n;++i)
        p[i].clear();
}

void out()
{
    int ct=0;
    for(int i=1;i<=n;++i)
        if(c[i]==t+1)
            ct++;
    if(ct<=n/2){
        pri(ct);
        prn();
        for(int i=1;i<=n;++i){
            if(c[i]==t+1)
                printf("%d ",i);
        }
        prn();
    }
    else{
        pri(n-ct);
        prn();
        for(int i=1;i<=n;++i){
            if(c[i]==t+1+maxn)
                printf("%d ",i);
        }
        prn();
    }
}

void debug()
{
    cout<<t<<endl;
    for(int i=1;i<=n;++i)
        cout<<c[i]<<" ";
    cout<<endl;
}

int main()
{
    sci(t);
    while(t--){
        scii(n,m);
        init();
        while(m--){
            scii(x,y);
            p[x].pb(y);
            p[y].pb(x);
        }
        dfs(1,t+1);
        out();
        //debug();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
bool vis[maxn];
vector<ll> p[maxn];
vector<ll> as;
ll cnt[maxn];
struct edge
{
    ll x,v;
}e[maxn];

bool cmp(edge a,edge b)
{
    return a.v>b.v;
}

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        memset(vis,0,sizeof(vis));
        memset(e,0,sizeof(e));
        memset(cnt,0,sizeof(cnt));
        re(i,1,n)
            p[i].clear();
        as.clear();
        while(m--){
            scll(x,y);
            p[x].pub(y);
            p[y].pub(x);
            cnt[x]++;
            cnt[y]++;
        }
        re(i,1,n)
        {
            e[i].x=i;
            e[i].v=cnt[i];
        }
        sort(e+1,e+1+n,cmp);
        re(i,1,n)
            if(p[i].size()==0)
                as.pub(i),vis[i]=true;
        re(i,1,n)
        {
            if(vis[e[i].x])
                continue;
            vis[e[i].x]=true;
            as.pub(e[i].x);
            if(as.size()==n/2)
                break;
            fo(j,0,p[e[i].x].size())
                vis[p[e[i].x][j]]=true;
        }
        printf("%d\n",as.size());
        fo(i,0,as.size())
            printf("%lld ",as[i]);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
ll cnt[maxn],as[maxn];

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        memset(cnt,0,sizeof(cnt));
        memset(as,0,sizeof(as));
        while(m--){
            scll(x,y);
            cnt[x]++;
            cnt[y]++;
        }
        ll ix=0;
        re(i,1,n)
        {
            if(ix>=n/4+1)
                break;
            as[ix]=i;
            ix++;
        }
        rre(i,n,1)
        {
            if(ix>=n/2)
                break;
            as[ix]=i;
            ix++;
        }
        printf("%lld\n",ix);
        fo(i,0,ix)
            printf("%lld ",as[i]);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
bool vis[maxn];
vector<ll> p[maxn];
vector<ll> as;
ll cnt[maxn];
struct edge
{
    ll x,v;
}e[maxn];

bool cmp(edge a,edge b)
{
    return a.v>b.v;
}

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        memset(cnt,0,sizeof(cnt));
        as.clear();
        /*
        memset(vis,0,sizeof(vis));
        memset(e,0,sizeof(e));
        re(i,1,n)
            p[i].clear();
        re(i,1,n)
            if(p[i].size()==0)
                as.pub(i),vis[i]=true;
        re(i,1,n)
        {
            if(vis[e[i].x])
                continue;
            vis[e[i].x]=true;
            as.pub(e[i].x);
            if(as.size()==n/2)
                break;
            fo(j,0,p[e[i].x].size())
                vis[p[e[i].x][j]]=true;
        }
        */
        while(m--){
            scll(x,y);
            /*
            p[x].pub(y);
            p[y].pub(x);
            */
            cnt[x]++;
            cnt[y]++;
        }
        re(i,1,n)
            if(cnt[i]==0)
                as.pub(i);
        re(i,1,n)
        {
            e[i].x=i;
            e[i].v=cnt[i];
        }
        sort(e+1,e+1+n,cmp);
        re(i,1,n)
        {
            if(e[i].v!=0){
                as.pub(e[i].x);
                if(as.size()==n/2)
                    break;
            }
        }
        printf("%d\n",as.size());
        fo(i,0,as.size())
            printf("%lld ",as[i]);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=200005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
ll cnt[maxn],as[maxn];

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        while(m--)
            scll(x,y);
        prl(n/2);
        prn();
        re(i,1,n/4+1)
            printf("%d ",i);
        rre(i,n,n+1-(n/2-n/4-1))
            printf("%d ",i);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define pri(a) printf("%d",a)
#define prn() printf("\n");
#define pb(a) push_back(a)
using namespace std;
const int maxn=200005;

int t,n,m,x,y;
vector<int> p[maxn];
int c[maxn];

void dfs(int i,int color)
{
    if(c[i]==t||c[i]==t*2+2)
        return;
    c[i]=color;
    for(int j=0;j<p[i].size();++j)
        dfs(p[i][j],t*3+2-color);
}

void init()
{
    for(int i=1;i<=n;++i)
        p[i].clear();
}

void out()
{
    int ct=0;
    for(int i=1;i<=n;++i)
        if(c[i]==t)
            ct++;
    if(ct<=n/2){
        pri(ct);
        prn();
        for(int i=1;i<=n;++i){
            if(c[i]==t)
                printf("%d ",i);
        }
        prn();
    }
    else{
        pri(n-ct);
        prn();
        for(int i=1;i<=n;++i){
            if(c[i]==t*2+2)
                printf("%d ",i);
        }
        prn();
    }
}

void debug()
{
    cout<<t<<endl;
    for(int i=1;i<=n;++i)
        cout<<c[i]<<" ";
    cout<<endl;
}

int main()
{
    sci(t);
    while(t--){
        scii(n,m);
        init();
        while(m--){
            scii(x,y);
            p[x].pb(y);
            p[y].pb(x);
        }
        dfs(1,t);
        out();
        //debug();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=200005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
ll cnt[maxn],as[maxn];

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        while(m--)
            scll(x,y);
        prl(n/2);
        prn();
        re(i,1,n/2)
            printf("%d ",i);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
bool vis[maxn];
vector<ll> p[maxn];
vector<ll> as;

int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m;
        memset(vis,0,sizeof(vis));
        re(i,1,n)
            p[i].clear();
        as.clear();
        while(m--){
            cin>>x>>y;
            p[x].pub(y);
            p[y].pub(x);
        }
        re(i,1,n)
            if(p[i].size()==0)
                as.pub(i),vis[i]=true;
        re(i,1,n)
        {
            if(vis[i])
                continue;
            vis[i]=true;
            as.pub(i);
            if(as.size()==n/2)
                break;
            fo(j,0,p[i].size())
                vis[p[i][j]]=true;
        }
        cout<<as.size()<<endl;
        fo(i,0,as.size())
            cout<<as[i]<<" ";
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=200005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;

int main()
{
    scl(t);
    while(t--){
        set<ll> s;
        scll(n,m);
        while(m--){
            scll(x,y);
            if(s.size()<n/2){
                if(s.count(x)||s.count(y));
                else
                    s.insert(x);
            }
        }
        printf("%d\n",s.size());
        for(auto i:s)
            printf("%lld ",i);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
bool vis[maxn];
vector<ll> p[maxn];
vector<ll> as;
ll cnt[maxn];
struct edge
{
    ll x,v;
}e[maxn];

bool cmp(edge a,edge b)
{
    return a.v>b.v;
}

int main()
{
    scl(t);
    while(t--){
        scll(n,m);
        memset(cnt,0,sizeof(cnt));
        as.clear();
        /*
        memset(e,0,sizeof(e));
        memset(vis,0,sizeof(vis));
        re(i,1,n)
            p[i].clear();
        re(i,1,n)
            if(p[i].size()==0)
                as.pub(i),vis[i]=true;
        re(i,1,n)
        {
            if(vis[e[i].x])
                continue;
            vis[e[i].x]=true;
            as.pub(e[i].x);
            if(as.size()==n/2)
                break;
            fo(j,0,p[e[i].x].size())
                vis[p[e[i].x][j]]=true;
        }
        */
        while(m--){
            scll(x,y);
            /*
            p[x].pub(y);
            p[y].pub(x);
            */
            cnt[x]++;
            cnt[y]++;
        }
        re(i,1,n)
            if(cnt[i]==0)
                as.pub(i);
        /*
        re(i,1,n)
        {
            e[i].x=i;
            e[i].v=cnt[i];
        }
        sort(e+1,e+1+n,cmp);
        re(i,1,n)
        {
            if(e[i].v!=0){
                as.pub(e[i].x);
                if(as.size()==n/2)
                    break;
            }
        }
        */
        re(i,1,n)
        {
            if(cnt[i]!=0){
                as.pub(i);
                if(as.size()==n/2)
                    break;
            }
        }
        printf("%d\n",as.size());
        fo(i,0,as.size())
            printf("%lld ",as[i]);
        prn();
    }
    return 0;
}


#include <bits/stdc++.h>
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sci(a) scanf("%d",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define scl(a) scanf("%lld",&a)
#define prd(a) printf("%lf",a)
#define prc(a) printf("%c",a)
#define prs(a) printf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%lld",a)
#define prn() printf("\n")
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define endl "\n"
#define debug(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll maxn=500005;
const ll inf=0x3f3f3f3f;
const double pi=3.1415926535;
const double esp=1e-10;
const int mod=10007;
template <typename t>
t mmax(t a,t b,t c){return max(a,max(b,c));}
template <typename t>
t mmin(t a,t b,t c){return min(a,min(b,c));}

ll t,n,m,x,y;
bool vis[maxn];
vector<ll> p[maxn];
vector<ll> as;
ll cnt[maxn];
struct edge
{
    ll x,v;
}e[maxn];

bool cmp(edge a,edge b)
{
    return a.v>b.v;
}

int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m;
        memset(vis,0,sizeof(vis));
        memset(e,0,sizeof(e));
        memset(cnt,0,sizeof(cnt));
        re(i,1,n)
            p[i].clear();
        as.clear();
        while(m--){
            cin>>x>>y;
            p[x].pub(y);
            p[y].pub(x);
            cnt[x]++;
            cnt[y]++;
        }
        re(i,1,n)
        {
            e[i].x=i;
            e[i].v=cnt[i];
        }
        sort(e+1,e+1+n,cmp);
        re(i,1,n)
            if(p[i].size()==0)
                as.pub(i),vis[i]=true;
        re(i,1,n)
        {
            if(vis[e[i].x])
                continue;
            vis[e[i].x]=true;
            as.pub(e[i].x);
            if(as.size()==n/2)
                break;
            fo(j,0,p[e[i].x].size())
                vis[p[e[i].x][j]]=true;
        }
        cout<<as.size()<<endl;
        fo(i,0,as.size())
            cout<<as[i]<<" ";
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<ll>adj[200005];
ll visit[200005];
ll dist[200005];
vector<ll> bfs(ll s,ll n)
{
    queue<ll>Q;
    Q.push(s);
    visit[s]=1;
    dist[s]=0;
    ll cnt=0;
    vector<ll>vct;
    vct.push_back(s);cnt++;if(cnt==n/2) return vct;
    cnt++;
    while(!Q.empty())
    {
        ll u=Q.front();Q.pop();
        ll sz=adj[u].size();
        for(ll i=0;i<sz;i++)
        {
            ll v=adj[u][i];
            if(visit[v]==0)
            {
                visit[v]=1;
                dist[v]=dist[u]+1;
                Q.push(v);
                if(dist[v]%2==0)
                {

                    vct.push_back(v);
                    cnt++;
                    if(cnt==n/2)
                        return vct;
                }

            }
        }
    }
    return vct;
}
void clear_all(ll n)
{
    for(ll i=0;i<n;i++)
    {
        adj[i].clear();
        visit[i]=0;
        dist[i]=0;
    }
    return;
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {

      cin>>n>>m;
      clear_all(n);
    ll k=1,ans=0;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%d %d",&u,&v);
          adj[u].push_back(v);
          adj[v].push_back(u);
           ll sz1=adj[u].size();
           ll sz2=adj[v].size();
           if(ans<sz1)
           {
             ans=sz1;
             k=u;
           }
           if(ans<sz2)
           {
               ans=sz2;
               k=v;
           }

      }

     vector<ll>vct;
    vct= bfs(k,n);
    ll sz=vct.size();
    cout<<sz<<endl;
    for(i=0;i<sz;i++)
        cout<<vct[i]<<" ";
    cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<ll>adj[200005];
ll visit[200005];
ll dist[200005];
vector<ll> bfs(ll s,ll n)
{
    queue<ll>Q;
    Q.push(s);
    visit[s]=1;
    dist[s]=0;
    ll cnt=0;
    vector<ll>vct;
    vct.push_back(s);cnt++;if(cnt==n/2) return vct;
    cnt++;
    while(!Q.empty())
    {
        ll u=Q.front();Q.pop();
        ll sz=adj[u].size();
        for(ll i=0;i<sz;i++)
        {
            ll v=adj[u][i];
            if(visit[v]==0)
            {
                visit[v]=1;
                dist[v]=dist[u]+1;
                Q.push(v);
                if(dist[v]%2==0)
                {

                    vct.push_back(v);
                    cnt++;
                    if(cnt==n/2)
                        return vct;
                }

            }
        }
    }
}
void clear_all(ll n)
{
    for(ll i=0;i<n;i++)
    {
        adj[i].clear();
        visit[i]=0;
        dist[i]=0;
    }
    return;
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {

      cin>>n>>m;
      clear_all(n);
    ll k=1,ans=0;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%d %d",&u,&v);
          adj[u].push_back(v);
          adj[v].push_back(u);
           ll sz1=adj[u].size();
           ll sz2=adj[v].size();
           if(ans<sz1)
           {
             ans=sz1;
             k=u;
           }
           if(ans<sz2)
           {
               ans=sz2;
               k=v;
           }

      }

     vector<ll>vct;
    vct= bfs(k,n);
    ll sz=vct.size();
    cout<<sz<<endl;
    for(i=0;i<sz;i++)
        cout<<vct[i]<<" ";
    cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
bool comp(ll u,ll v)
{
    return (adj[u].size()>adj[v].size());
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {

      cin>>n>>m;
      for(i=0;i<n;i++) adj[i].clear();
      vector<ll>vct;
       set<ll>st;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%lld %lld",&u,&v);
          if(st.find(u)==st.end())
          {
              st.insert(u);
              vct.push_back(u);
          }
           if(st.find(v)==st.end())
          {
              st.insert(v);
              vct.push_back(v);
          }

          adj[u].push_back(v);
          adj[v].push_back(u);

      }
     sort(vct.begin(),vct.end(),comp);
     cout<<n/2<<endl;
     for(i=0;i<n/2;i++)
        cout<<vct[i]<<" ";
        cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
ll visit[200005];
ll dist[200005];
vector<ll> bfs(ll s,ll n)
{
    queue<ll>Q;
    Q.push(s);
    visit[s]=1;
    dist[s]=0;
    ll cnt=0;
    vector<ll>vct;
    vct.push_back(s);cnt++;if(cnt==n/2) return vct;
    cnt++;
    while(!Q.empty())
    {
        ll u=Q.front();Q.pop();
        ll sz=adj[u].size();
        for(ll i=0;i<sz;i++)
        {
            ll v=adj[u][i];
            if(visit[v]==0)
            {
                visit[v]=1;
                dist[v]=dist[u]+1;
                Q.push(v);
                if(dist[v]%2==0)
                {

                    vct.push_back(v);
                    cnt++;
                    if(cnt==n/2)
                        return vct;
                }

            }
        }
    }
    return vct;
}
void clear_all(ll n)
{
    for(ll i=0;i<n;i++)
    {
        adj[i].clear();
        dist[i]=visit[i]=0;
    }
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {

      cin>>n>>m;
      clear_all(n);
    ll k=1,ans=0;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%lld %lld",&u,&v);
          adj[u].push_back(v);
          adj[v].push_back(u);
           ll sz1=adj[u].size();
           ll sz2=adj[v].size();
           if(ans<sz1)
           {
             ans=sz1;
             k=u;
           }
           if(ans<sz2)
           {
               ans=sz2;
               k=v;
           }

      }

     vector<ll>vct;
    vct= bfs(k,n);
    ll sz=vct.size();
    cout<<sz<<endl;
    for(i=0;i<sz;i++)
        cout<<vct[i]<<" ";
    cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
int p[200005];
vector<int>adj[200005];
int visit[200005];
int findd(int x)
{
    if(p[x]==x)
        return x;
    else return p[x]=findd(p[x]);
}
int cnt=0;
vector<ll>odd;
vector<ll>even;
void dfs(ll s,ll d,ll n)
{
    visit[s]=1;
    if(d%2==0)
     even.push_back(s);
     else odd.push_back(s);
    ll sz=adj[s].size();
    for(ll i=0;i<sz;i++)
    {
        ll v=adj[s][i];
        if(visit[v]==0)
        {   visit[v]=1;
            dfs(v,d+1,n);

        }
    }
}
int main()
{
    int tc,n,m,i;
    cin>>tc;
    while(tc--)
    {  cnt=0;
        cin>>n>>m;
        for(i=0;i<=n;i++)
            {p[i]=i;adj[i].clear();visit[i]=0;}
            even.clear();odd.clear();
      int u,v,ans=0,k;
      for(i=0;i<m;i++)
      {
          cin>>u>>v;
          if(findd(u)!=findd(v))
          {
              adj[u].push_back(v);
              adj[v].push_back(u);
              p[findd(u)]=findd(v);
          }
          if(ans<adj[u].size())
          {
              ans=adj[u].size();
              k=u;
          }
           if(ans<adj[v].size())
          {
              ans=adj[v].size();
              k=v;
          }
      }
     dfs(k,-1,n);
     if(even.size()>odd.size())
     {
         ll sz=even.size();
         cout<<min(n/2,sz)<<endl;
         sz=min(n/2,sz);
         for(i=0;i<sz;i++)
            cout<<even[i]<<" ";
         cout<<endl;
     }
    else
     {
        ll sz=odd.size();
        sz=min(n/2,sz);
         for(i=0;i<sz;i++)
            cout<<odd[i]<<" ";
         cout<<endl;
     }

    }

}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<ll>adj[200005];
ll visit[200005];
ll take[200005];
set<ll>st;
set<ll>ans;
void dfs(ll s,ll p=-1)
{
    visit[s]=1;
    ll k=0;
    ll sz=adj[s].size();
    for(ll i=0;i<sz;i++)
    {
        ll v=adj[s][i];
        if(visit[v]==0)
        {
            k=1;
            visit[v]=1;
            dfs(v,s);
        }
    }
    if(k==0&&take[p]==0)
    {
        st.erase(p);
        take[p]=1;
        ans.insert(p);
        ll sz=adj[p].size();
        for(ll i=0;i<sz;i++)
        {
            ll u=adj[p][i];
            st.erase(u);
        }
    }
}
int main()
{
  ll tc,n,m,i;
  cin>>tc;
  while(tc--)
  {
      cin>>n>>m;
      st.clear();ans.clear();
      for(i=0;i<=n;i++){
        adj[i].clear();
        visit[i]=0;
        take[i]=0;
      }
      for(i=0;i<m;i++)
      {
          ll u,v;
          cin>>u>>v;
          st.insert(u);st.insert(v);
          adj[u].push_back(v);
          adj[v].push_back(u);
      }
      dfs(1);
      set<ll>::iterator itr;

    for(itr=st.begin();itr!=st.end();itr++)
    {
        if(st.find(*itr)!=st.end())
        {
            ans.insert(*itr);
            for(ll i=0;i<adj[*itr].size();i++)
                st.erase(adj[*itr][i]);
        }
    }
    cout<<ans.size()<<endl;
  for(itr=ans.begin();itr!=ans.end();itr++)
    cout<<*itr<<" ";
  cout<<endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
ll visit[200005];
ll dist[200005];
vector<ll> bfs(ll s,ll n)
{
    queue<ll>Q;
    Q.push(s);
    visit[s]=1;
    dist[s]=0;
    ll cnt=0;
    vector<ll>vct;
    vct.push_back(s);cnt++;if(cnt==n/2) return vct;
    cnt++;
    while(!Q.empty())
    {
        ll u=Q.front();Q.pop();
        ll sz=adj[u].size();
        for(ll i=0;i<sz;i++)
        {
            ll v=adj[u][i];
            if(visit[v]==0)
            {
                visit[v]=1;
                dist[v]=dist[u]+1;
                Q.push(v);
                if(dist[v]%2==0)
                {

                    vct.push_back(v);
                    cnt++;
                    if(cnt==n/2)
                        return vct;
                }

            }
        }
    }
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {
      memset(adj,0,sizeof(adj));
      memset(visit,0,sizeof(dist));
      memset(dist,0,sizeof(dist));
      cin>>n>>m;
    ll k=1,ans=0;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%lld %lld",&u,&v);
          adj[u].push_back(v);
          adj[v].push_back(u);
           ll sz1=adj[u].size();
           ll sz2=adj[v].size();
           if(ans<sz1)
           {
             ans=sz1;
             k=u;
           }
           if(ans<sz2)
           {
               ans=sz2;
               k=v;
           }

      }

     vector<ll>vct;
    vct= bfs(k,n);
    ll sz=vct.size();
    cout<<sz<<endl;
    for(i=0;i<sz;i++)
        cout<<vct[i]<<" ";
    cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
vector<ll>adj2[200005];
ll visit[200005]={0};
void dfs(ll s)
{
    visit[s]=1;
    ll sz=adj2[s].size();
    for(ll i=0;i<sz;i++)
    {  ll v=adj2[s][i];
        if(!visit[v])
        {
            adj[s].push_back(v);
            adj[v].push_back(s);
            dfs(v);
        }
    }
}
bool comp(ll u,ll v)
{
    return (adj[u].size()>adj[v].size());
}
void clear_all(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        adj[i].clear();
        adj2[i].clear();
        visit[i]=0;
    }
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {
      cin>>n>>m;
      vector<ll>vct;
      clear_all(n);
      ll take[200005]={0};
      for(i=0;i<m;i++)
      {
          ll u,v;
          cin>>u>>v;
          if(take[u]==0)
          {
              vct.push_back(u);
              take[u]=1;
          }
          if(take[v]==0)
          {
              vct.push_back(v);
              take[v]=1;
          }
          k=u;
          adj2[u].push_back(v);
          adj2[v].push_back(u);
      }
     dfs(k);
     cout<<n/2<<endl;
     sort(vct.begin(),vct.end(),comp);
     for(i=0;i<n/2;i++)
        cout<<vct[i]<<" ";
     cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
vector<ll>adj2[200005];
ll visit[200005]={0};
void dfs(ll s)
{
    visit[s]=1;
    ll sz=adj2[s].size();
    for(ll i=0;i<sz;i++)
    {  ll v=adj2[s][i];
        if(!visit[v])
        {
            adj[s].push_back(v);
            adj[v].push_back(s);
            dfs(v);
        }
    }
}
bool comp(ll u,ll v)
{
    return (adj[u].size()>adj[v].size());
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {   memset(visit,0,sizeof(visit));
      memset(adj,0,sizeof(adj));
      memset(adj2,0,sizeof(adj2));
      cin>>n>>m;
      vector<ll>vct;
      ll take[200005]={0};
      for(i=0;i<m;i++)
      {
          ll u,v;
          cin>>u>>v;
          if(take[u]==0)
          {
              vct.push_back(u);
              take[u]=1;
          }
          if(take[v]==0)
          {
              vct.push_back(v);
              take[v]=1;
          }
          k=u;
          adj2[u].push_back(v);
          adj2[v].push_back(u);
      }
     dfs(k);
     cout<<n/2<<endl;
     sort(vct.begin(),vct.end(),comp);
     for(i=0;i<n/2;i++)
        cout<<vct[i]<<" ";
     cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
ll visit[200005];
ll dist[200005];
vector<ll> bfs(ll s,ll n)
{
    queue<ll>Q;
    Q.push(s);
    visit[s]=1;
    dist[s]=0;
    ll cnt=0;
    vector<ll>vct;
    vct.push_back(s);cnt++;if(cnt==n/2) return vct;
    cnt++;
    while(!Q.empty())
    {
        ll u=Q.front();Q.pop();
        ll sz=adj[u].size();
        for(ll i=0;i<sz;i++)
        {
            ll v=adj[u][i];
            if(visit[v]==0)
            {
                visit[v]=1;
                dist[v]=dist[u]+1;
                Q.push(v);
                if(dist[v]%2==0)
                {

                    vct.push_back(v);
                    cnt++;
                    if(cnt==n/2)
                        return vct;
                }

            }
        }
    }
    return vct;
}
void clear_all(ll n)
{
    for(ll i=0;i<n;i++)
    {
        adj[i].clear();
        dist[i]=visit[i]=0;
    }
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {

      cin>>n>>m;
      clear_all(n);
    ll k=1,ans=0;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%lld %lld",&u,&v);
          adj[u].push_back(v);
          adj[v].push_back(u);

      }

     vector<ll>vct;
    vct= bfs(1,n);
    ll sz=vct.size();
    cout<<sz<<endl;
    for(i=0;i<sz;i++)
        cout<<vct[i]<<" ";
    cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
ll visit[200005]={0};
bool comp(ll u,ll v)
{
    return (adj[u].size()>adj[v].size());
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {   memset(visit,0,sizeof(visit));
      memset(adj,0,sizeof(adj));

      cin>>n>>m;
      vector<ll>vct;
       set<ll>st;
      for(i=0;i<m;i++)
      {
          ll u,v;
          cin>>u>>v;
          if(st.find(u)==st.end())
          {
              st.insert(u);
              vct.push_back(u);
          }
           if(st.find(v)==st.end())
          {
              st.insert(v);
              vct.push_back(v);
          }

          adj[u].push_back(v);
          adj[v].push_back(u);

      }
     sort(vct.begin(),vct.end(),comp);
     cout<<n/2<<endl;
     for(i=0;i<n/2;i++)
        cout<<vct[i]<<" ";
        cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>adj[200005];
bool comp(ll u,ll v)
{
    return (adj[u].size()>adj[v].size());
}
int main()
{
  ll tc,n,m,i,k;
  cin>>tc;
  while(tc--)
  {
      memset(adj,0,sizeof(adj));

      cin>>n>>m;
      vector<ll>vct;
       set<ll>st;
      for(i=0;i<m;i++)
      {
          ll u,v;
          scanf("%lld %lld",&u,&v);
          if(st.find(u)==st.end())
          {
              st.insert(u);
              vct.push_back(u);
          }
           if(st.find(v)==st.end())
          {
              st.insert(v);
              vct.push_back(v);
          }

          adj[u].push_back(v);
          adj[v].push_back(u);

      }
     sort(vct.begin(),vct.end(),comp);
     cout<<n/2<<endl;
     for(i=0;i<n/2;i++)
        cout<<vct[i]<<" ";
        cout<<endl;

  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==1)
            dfs(c[i][0]);
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        if(sum*2>n)
		{
			cout<<n<<"!"<<m<<endl;
			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];
bool cmp(node a,node b)
{
	return a.v<b.v;
}

int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int max=0;
		int gg=1;
		cin>>n>>m;
		int x,y;

		p.clear();

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n;i>=1;i--)
		{
			if(v[a[i].i]==0)
			dfs(a[i].i);
		}
		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];
bool cmp(node a,node b)
{
	return a.v<b.v;
}
int n,m;
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		cin>>n>>m;
		int x,y;

		memset(a,0,sizeof(a));

		for(int i=0;i<m;i++)
		{
			cin>>x>>y;
			a[x].i=x;
			a[y].i=y;
			a[x].v++;
			a[y].v++;
		}
		sort(a+1,a+n+1,cmp);
		cout<<n/2<<endl;

		cout<<a[n].i<<" ";

		for(int i=1;i<n/2;i++)
		{
			cout<<a[i].i<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=0;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max&&v[x]==1)
					{
						max=c[x].size();
						temp=x;
					}
					else if(c[x].size()>=max&&v[x]==0)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(temp!=0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }
        /*
		if(sum*2>n)
		{
			for(int i=0;i<=n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}

			cout<<endl;
		}
		*/
        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005];
int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

	for(x=x+1;v[x]==1;x++)
	{

	}

	if(x<=n&&v[x]==0)
	dfs(x);
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		cin>>n>>m;
		int x,y;

		p.clear();

		for(int i=1;i<=n;i++)
		c[i].clear();
		memset(v,0,sizeof(v));

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

		sum=0;

		dfs(1);

		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];

bool cmp(node a,node b)
{
	return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
	ans[k++]=x;
	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		k=0;
		cin>>n>>m;
		int x,y;

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n;i>=1;i--)
		{
			if(v[i]==0)
			dfs(i);
		}

		cout<<sum<<endl;

		for(int i=0;i<k; i++)
		{
			cout<<ans[i]<<" ";
		}

		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=1;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max&&v[x]==0)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(v[temp]==0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

		if(sum*2>n)
		{
			for(int i=1;i<=n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}

			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];
bool cmp(node a,node b)
{
	return a.v<b.v;
}

int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int max=0;
		int gg=1;
		cin>>n>>m;
		int x,y;

		p.clear();

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n-1;i>=0;i--)
		{
			dfs(a[i].i);
		}
		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];

bool cmp(node a,node b)
{
	return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
	ans[k++]=x;
	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		k=0;
		cin>>n>>m;
		int x,y;

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n;i>=1;i--)
		{
			if(v[a[i].i]==0)
			dfs(a[i].i);
		}

		cout<<sum<<endl;

		for(int i=0;i<k; i++)
		{
			cout<<ans[k]<<" ";
		}

		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=1;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max&&v[x]==0)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(v[temp]==0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

		if(sum*2>n)
		{
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}
			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=1;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max&&v[x]==0)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(v[temp]==0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
            a[i].i=i;
            a[i].v=0;
        }

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

        sum=0;
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==1)
            dfs(c[i][0]);
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        if(sum*2>n)
		{
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!!!"<<i<<"@@@"<<j;
				}
			}
			cout<<endl;
		 }
        cout<<sum<<endl;

        for(int i=0;i<k; i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
            a[i].i=i;
            a[i].v=0;
        }

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

        sum=0;
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==1)
            dfs(c[i][0]);
        }
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        cout<<sum<<endl;

        for(int i=0;i<k; i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
            a[i].i=i;
            a[i].v=0;
        }

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

        sum=0;
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==1)
            dfs(c[i][0]);
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        if(sum*2>n)
		{
			for(i=0;i<n;i++)
			{
				for(int j=0;i<c[i].size();i++)
				{
					cout<<c[i][j];
				}
			}
		 }

        cout<<sum<<endl;

        for(int i=0;i<k; i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];
bool cmp(node a,node b)
{
	return a.v<b.v;
}

int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int max=0;
		int gg=1;
		cin>>n>>m;
		int x,y;

		p.clear();

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n-1;i>=0;i--)
		{
			if(v[a[i].i]==0)
			dfs(a[i].i);
		}
		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
            a[i].i=i;
            a[i].v=0;
        }

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

        sum=0;
        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==1)
            dfs(c[i][0]);
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        if(sum*2>n)
		{
			cout<<"100"<<endl;
		 }

        cout<<sum<<endl;

        for(int i=0;i<k; i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int v;
	int i;
};
node a[200005];

bool cmp(node a,node b)
{
	return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
	ans[k++]=x;
	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		k=0;
		cin>>n>>m;
		int x,y;

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
			a[i].i=i;
			a[i].v=0;
		}

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

		sort(a+1,a+n+1,cmp);

		sum=0;

		for(int i=n;i>=1;i--)
		{
			if(v[a[i].i]==0)
			dfs(a[i].i);
		}

		cout<<sum<<endl;

		for(int i=0;i<k; i++)
		{
			cout<<ans[i]<<" ";
		}

		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005];
int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

	for(x=x+1;v[x]==1;x++)
	{

	}

	if(x<=n&&v[x]==0)
	dfs(x);
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int max=0;
		int gg=1;
		cin>>n>>m;
		int x,y;

		p.clear();

		for(int i=1;i<=n;i++)
		{
			c[i].clear();
			v[i]=0;
		}

		for(int i=0;i<m;i++)
		{
			cin>>x>>y;
			c[x].push_back(y);
			c[y].push_back(x);
			if(c[x].size()>max)
			{
				max=c[x].size();
				gg=x;
			}
			if(c[y].size()>max)
			{
				max=c[y].size();
				gg=y;
			}
		}

		sum=0;

		dfs(gg);
		if(v[1]==0)
		dfs(1);
		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=0;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(temp!=0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

		if(sum*2>n)
		{
			cout<<n<<m;
			for(int i=0;i<=n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}

			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005];
int v[200005];
vector<int> c[200005];
vector<int> p;
int sum=0;
int n,m;
void dfs(int x)
{
	p.push_back(x);

	v[x]=1;
	sum++;

	for(int i=0; i<c[x].size(); i++)
	{
		v[c[x][i]]=1;
	}

	for(x=x+1;v[x]==1;x++)
	{

	}

	if(x<=n&&v[x]==0)
	dfs(x);
}
int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		cin>>n>>m;
		int x,y;

		p.clear();
		for(int i=0;i<n;i++)
		c[i].clear();
		memset(v,0,sizeof(v));

		for(int i=0;i<m;i++)
		{
			cin>>x>>y;
			if(x<y)
			c[x].push_back(y);
			else
			c[y].push_back(x);
		}

		sum=0;

		dfs(1);

		cout<<sum<<endl;
		for(int i=0;i<p.size(); i++)
		{
			cout<<p[i]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=-1;
            	int temp=1;
            	for(int j=0;j<c[i].size();j++)
				{
					if(c[c[i][j]].size()>max&&v[c[i][j]]==0)
					{
						max=c[c[i][j]].size();
						temp=c[i][j];
					}
				}
				if(v[temp]==0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=0;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(temp!=0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

		if(sum*2>n)
		{
			for(int i=0;i<=n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}

			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int v;
    int i;
};
node a[200005];

bool cmp(node a,node b)
{
    return a.v<b.v;
}

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

int sum=0;
int n,m;
int k;

void dfs(int x)
{
    ans[k++]=x;
    v[x]=1;
    sum++;

    for(int i=0; i<c[x].size(); i++)
    {
        v[c[x][i]]=1;
    }
}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        k=0;
        cin>>n>>m;
        int x,y;

        for(int i=1;i<=n;i++)
        {
            c[i].clear();
            v[i]=0;
        }

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

        sum=0;

        int min=9999999;

        for(int i=n;i>=1;i--)
        {
            if(c[i].size()<min)
            min=c[i].size();
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0&&c[i].size()==min)
            {
            	int max=0;
            	int temp=0;
            	int j=0;
            	for(;j<c[i].size();j++)
				{
					int x=c[i][j];
					if(c[x].size()>max)
					{
						max=c[x].size();
						temp=x;
					}
				}
				if(temp!=0)
				dfs(temp);
            }
        }

        for(int i=n;i>=1;i--)
        {
            if(v[i]==0)
            dfs(i);
        }

		if(sum*2>n)
		{
			for(int i=1;i<=n;i++)
			{
				for(int j=0;j<c[i].size();j++)
				{
					cout<<c[i][j]<<"!"<<i<<"@"<<j;
				}
			}

			cout<<endl;
		}

        cout<<sum<<endl;

        for(int i=0;i<k;i++)
        {
            cout<<ans[i]<<" ";
        }

        cout<<endl;
    }
}


//In the Name of God

#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstring>
#define int long long
#define nm first
#define cost second.first
#define prob second.second

using namespace std;

const int maxf=128,inf=1e18+7;
int n,m,b,N,ans=inf,dp[2][1<<21];
pair<int,pair<int,int> > f[maxf];

main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin>>m>>n>>b;
  N=1ll<<n;
  for(int x,i=0;i<m;i++)
    {
      cin>>f[i].cost>>f[i].nm>>x;
      for(int pid;x--;)
	{
	  cin>>pid;
	  f[i].prob+=1ll<<(pid-1);
	}
    }
  sort(f,f+m);
  memset(dp,127,sizeof dp);
  dp[0][0]=0;
  for(int s,t,i=0;i<m;i++)
    {
      s=i&1;
      t=1-s;
      for(int mask=0;mask<N;mask++)
	dp[t][mask]=min(dp[s][mask],dp[s][mask&(~f[i].prob)]+f[i].cost);
      ans=min(ans,dp[t][N-1]+f[i].nm*b);
    }
  if(ans!=inf)
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstring>
#define int long long
#define nm first
#define cost second.first
#define prob second.second

using namespace std;

const int maxf=128,inf=1ll<<62;
int n,m,b,N,ans=inf,dp[2][1<<21];
pair<int,pair<int,int> > f[maxf];

main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin>>m>>n>>b;
  N=1ll<<n;
  for(int x,i=0;i<m;i++)
    {
      cin>>f[i].cost>>f[i].nm>>x;
      for(int pid;x--;)
	{
	  cin>>pid;
	  f[i].prob+=1ll<<(pid-1);
	}
    }
  sort(f,f+m);
  for(int i=1;i<N;i++)
    dp[0][i]=inf;
  dp[0][0]=0LL;
  for(int s,t,i=0;i<m;i++)
    {
      s=i&1;
      t=1-s;
      for(int mask=0;mask<N;mask++)
	{
	  dp[t][mask]=min(dp[s][mask],dp[s][mask&(~f[i].prob)]+f[i].cost);
	}
      ans=min(ans,dp[t][N-1]+f[i].nm*b);
    }
  if(ans<inf)
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstring>
#define int long long
#define nm first
#define cost second.first
#define prob second.second

using namespace std;

const int maxf=128,inf=1ll<<62;
int n,m,b,N,ans=inf,dp[2][1<<21];
pair<int,pair<int,int> > f[maxf];

main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin>>m>>n>>b;
  N=1ll<<n;
  for(int x,i=0;i<m;i++)
    {
      cin>>f[i].cost>>f[i].nm>>x;
      for(int pid;x--;)
	{
	  cin>>pid;
	  f[i].prob+=1ll<<(pid-1);
	}
    }
  sort(f,f+m);
  memset(dp,127,sizeof dp);
  dp[0][0]=0;
  for(int s,t,i=0;i<m;i++)
    {
      s=i&1;
      t=1-s;
      for(int mask=0;mask<N;mask++)
	dp[t][mask]=min(dp[s][mask],dp[s][mask&(~f[i].prob)]+f[i].cost);
      ans=min(ans,dp[t][N-1]+f[i].nm*b);
    }
  if(ans!=inf)
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
  return 0;
}


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct dude{
    long long x, k, mask;
};

long long n, m, b;
vector<dude> people[20];
long long memo[1<<20];
long long memob[1<<20];

long long dp(int mask){
    if(memo[mask] != -1) return memo[mask];
    int low = -1;
    for(int i=0; i<m; i++){
        if( (mask&(1<<i)) != 0){
            low = i;
            break;
        }
    }

    long long best = -1;
    long long bestb = -1;
    for(int i=0; i<people[low].size(); i++){
        int next = (mask&(~people[low][i].mask));
        long long tmp = dp(next);
        if(tmp == -1) continue;
        tmp += people[low][i].x;
        if(people[low][i].k > memob[next]){
            tmp += (people[low][i].k - memob[next])*b;
        }
        if(best == -1 || best > tmp){
            best = tmp;
            bestb = max(people[low][i].k, memob[next]);
        }
    }

    memo[mask] = best;
    memob[mask] = bestb;
    return best;
}

int main(){
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        int first = 20;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
            first = min(first, t2);
        }
        people[first-1].push_back(d);
    }

    memset(memo, -1, sizeof(memo));
    memset(memob, -1, sizeof(memob));
    memo[0] = 0;
    memob[0] = 0;

    printf("%I64d\n", dp( (1<<m)-1 ) );

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    long long x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    long long n, m, b;
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        bool push = true;
        for(int j=0; j<people.size(); j++){
            if(people[j].mask == d.mask){
                if(people[j].x + people[j].k*b > d.x + d.k*b){
                    people[j] = d;
                }
                push = false;
                break;
            }
        }
        if(push)
            people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<people.size(); i++){
        map<int, long long> *next = new map<int, long long>(*memo);
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    long long x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    long long n, m, b;
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<n; i++){
        map<int, long long> *next = new map<int, long long>(*memo);
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    long long x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    long long n, m, b;
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        bool push = true;
        for(int j=0; j<people.size(); j++){
            if(people[j].mask == d.mask){
                if(people[j].x > d.x  && people[j].k == d.k){
                    people[j] = d;
                }
                push = false;
                break;
            }
        }
        if(push)
            people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<people.size(); i++){
        map<int, long long> *next = new map<int, long long>(*memo);
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct dude{
    long long x, k, mask;
};

long long n, m, b;
vector<dude> people[20];
long long memo[1<<20];
long long memob[1<<20];

long long dp(int mask){
    if(memo[mask] != -1) return memo[mask];
    int low = -1;
    for(int i=0; i<m; i++){
        if( (mask&(1<<i)) != 0){
            low = i;
            break;
        }
    }

    long long best = -1;
    long long bestb = -1;
    for(int i=0; i<people[low].size(); i++){
        int next = (mask&(~people[low][i].mask));
        long long tmp = dp(next);
        if(tmp == -1) continue;
        tmp += people[low][i].x;
        if(people[low][i].k > memob[next]){
            tmp += (people[low][i].k - memob[next])*b;
        }
        if(best == -1 || best > tmp){
            best = tmp;
            bestb = max(people[low][i].k, memob[next]);
        }
    }

    memo[mask] = best;
    memob[mask] = bestb;
    return best;
}

int main(){
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        for(int j=0; j<m; j++){
            if((d.mask&(1<<j)) != 0){
                people[j].push_back(d);
            }
        }
    }

    memset(memo, -1, sizeof(memo));
    memset(memob, -1, sizeof(memob));
    memo[0] = 0;
    memob[0] = 0;

    printf("%I64d\n", dp( (1<<m)-1 ) );

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    int x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    int n, m, b;
    scanf("%d %d %d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%d %d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<n; i++){
        map<int, long long> *next = new map<int, long long>();
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    long long x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    long long n, m, b;
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        bool push = true;
        for(int j=0; j<people.size(); j++){
            if(people[j].mask == d.mask && people[j].k == d.k){
                if(people[j].x > d.x){
                    people[j] = d;
                }
                push = false;
                break;
            }
        }
        if(push)
            people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<people.size(); i++){
        map<int, long long> *next = new map<int, long long>(*memo);
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    long long x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

long long memo[1<<20];

int main(){
    long long n, m, b;
    scanf("%I64d %I64d %I64d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%I64d %I64d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        bool push = true;
        for(int j=0; j<people.size(); j++){
            if(people[j].mask == d.mask && people[j].k == d.k){
                if(people[j].x > d.x){
                    people[j] = d;
                }
                push = false;
                break;
            }
        }
        if(push)
            people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    // map<int, long long> *memo = new map<int, long long>();
    // (*memo)[0] = 0;
    memset(memo, -1, sizeof(memo));
    memo[0] = 0;

    long long ans = -1;
    for(int i=0; i<people.size(); i++){
        // map<int, long long> *next = new map<int, long long>(*memo);
        // for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
        for(int j=0; j<(1<<m); j++){
            if(memo[j] == -1) continue;
            // int mask = (it->first) | people[i].mask;
            int mask = (j | people[i].mask);
            // if( next->count( mask ) == 0){
                // (*next)[ mask ] = it->second + people[i].x;
            // }else{
                // (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            // }
            long long temp = memo[j] + people[i].x;
            if(memo[mask] == -1 || memo[mask] > temp){
                memo[mask] = temp;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = temp + people[i].k*b;
                else ans = min(ans, temp + people[i].k*b);
            }
        }
        // memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct dude{
    int x, k, mask;
};

struct CMP{
    bool operator()(dude a, dude b){
        return a.k < b.k;
    }
};

int main(){
    int n, m, b;
    scanf("%d %d %d", &n, &m, &b);
    vector<dude> people;
    for(int i=0; i<n; i++){
        dude d;
        int t;
        scanf("%d %d %d", &d.x, &d.k, &t);
        d.mask = 0;
        for(int j=0; j<t; j++){
            int t2;
            scanf("%d", &t2);
            d.mask |= (1<<(t2-1));
        }
        people.push_back(d);
    }

    sort(people.begin(), people.end(), CMP());

    map<int, long long> *memo = new map<int, long long>();
    (*memo)[0] = 0;

    long long ans = -1;
    for(int i=0; i<n; i++){
        map<int, long long> *next = new map<int, long long>(*memo);
        for(map<int, long long>::iterator it = memo->begin(); it != memo->end(); it++){
            int mask = (it->first) | people[i].mask;
            if( next->count( mask ) == 0){
                (*next)[ mask ] = it->second + people[i].x;
            }else{
                (*next)[ mask ] = min( (*next)[mask], it->second + people[i].x) ;
            }
            if(mask == ((1<<m)-1)){
                if(ans == -1) ans = it->second + people[i].x + people[i].k*b;
                else ans = min(ans, it->second + people[i].x + people[i].k*b);
            }
        }
        memo = next;
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

typedef long long LL;

struct P {
  int probs, money, mons;
};

int n, m, all;
P ps[101];
LL tbl[1 << 21];
LL b;

LL dynamic(int mask, int mcount) {
  LL &r = tbl[mask];
  if (r != -1) return r;
  if (!mask) return r = 0;

  r = -1;
  for (int i = 0; i < n; ++i) {
    if (mask & ps[i].probs) {
      //int nmcount = ps[i].mons > mcount ? ps[i].mons : mcount;
      LL diff = ps[i].mons > mcount ? ps[i].mons - mcount : 0;
      LL tmp = dynamic(mask & ~ps[i].probs, ps[i].mons);
      tmp += ps[i].money + diff * b;
      if (r == -1 || r > tmp) {
    r = tmp;
      }
    }
  }
  return r;
}

bool cmp(const P &a, const P &b) {
  return a.mons < b.mons;
}

int main() {
  all = 0;
  cin >> n >> m >> b;
  for (int i = 0; i < n; ++i) {
    int mi, mip;
    cin >> ps[i].money >> ps[i].mons >> mi;
    ps[i].probs = 0;
    for (int j = 0; j < mi; ++j) {
      cin >> mip;
      --mip;
      ps[i].probs |= (1 << mip);
      all |= (1 << mip);
    }
  }
  sort(ps, ps + n, cmp);
  if (all == (1 << m) - 1) {
    memset(tbl, -1, sizeof(tbl));
    cout << dynamic(all, 0) << endl;
  } else cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

typedef long long LL;

int n, m, all;
int probs[101];
int money[101];
int mons[101];
LL tbl[1 << 21];
LL b;

LL dynamic(int mask, int mcount) {
  LL &r = tbl[mask];
  if (r != -1) return r;
  if (!mask) return r = 0;

  r = -1;
  for (int i = 0; i < n; ++i) {
    if (mask & probs[i]) {
      int nmcount = mons[i] > mcount ? mons[i] : mcount;
      LL diff = mons[i] > mcount ? mons[i] - mcount : 0;
      LL tmp = dynamic(mask & ~probs[i], nmcount);
      tmp += money[i] + diff * b;
      if (r == -1 || r > tmp) {
    r = tmp;
      }
    }
  }
  return r;
}

int main() {
  all = 0;
  cin >> n >> m >> b;
  for (int i = 0; i < n; ++i) {
    int mi, mip;
    cin >> money[i] >> mons[i] >> mi;
    probs[i] = 0;
    for (int j = 0; j < mi; ++j) {
      cin >> mip;
      --mip;
      probs[i] |= (1 << mip);
      all |= (1 << mip);
    }
  }
  if (all == (1 << m) - 1) {
    memset(tbl, -1, sizeof(tbl));
    cout << dynamic(all, 0) << endl;
  } else cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

typedef long long LL;

struct P {
  int probs, money, mons;
};

int n, m, all;
P ps[101];
LL tbl[1 << 21];
LL b;

bool cmp(const P &a, const P &b) {
  return a.mons < b.mons;
}

int main() {
  all = 0;
  cin >> n >> m >> b;
  for (int i = 0; i < n; ++i) {
    int mi, mip;
    cin >> ps[i].money >> ps[i].mons >> mi;
    ps[i].probs = 0;
    for (int j = 0; j < mi; ++j) {
      cin >> mip;
      --mip;
      ps[i].probs |= (1 << mip);
      all |= (1 << mip);
    }
  }
  sort(ps, ps + n, cmp);
  if (all == (1 << m) - 1) {

    memset(tbl, -1, sizeof(tbl));
    tbl[0] = 0;
    LL best = -1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= all; ++j) {

    LL cost = tbl[j] == -1 ? -1 : tbl[j] + ps[i].money;
    if (cost != -1 && (tbl[j | ps[i].probs] == -1 || tbl[j | ps[i].probs] > cost)) {
      tbl[j | ps[i].probs] = cost;
    }

      }

      if (tbl[all] != -1 && (best == -1 || best > tbl[all] + b * ps[i].mons)) {
    best = tbl[all] + b * ps[i].mons;
      }

    }
    cout << best << endl;

  } else cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

typedef long long LL;

int n, m, b, all;
int probs[101];
int money[101];
int mons[101];
LL tbl[1 << 21];

LL dynamic(int mask, int mcount) {
  LL &r = tbl[mask];
  if (r != -1) return r;
  if (!mask) return r = 0;

  r = -1;
  for (int i = 0; i < n; ++i) {
    if (mask & probs[i]) {
      int nmcount = mons[i] > mcount ? mons[i] : mcount;
      int diff = mons[i] > mcount ? mons[i] - mcount : 0;
      LL tmp = dynamic(mask & ~probs[i], nmcount);
      tmp += money[i] + diff * b;
      if (r == -1 || r > tmp) {
    r = tmp;
      }
    }
  }
  return r;
}

int main() {
  all = 0;
  cin >> n >> m >> b;
  for (int i = 0; i < n; ++i) {
    int mi, mip;
    cin >> money[i] >> mons[i] >> mi;
    probs[i] = 0;
    for (int j = 0; j < mi; ++j) {
      cin >> mip;
      --mip;
      probs[i] |= (1 << mip);
      all |= (1 << mip);
    }
  }
  if (all == (1 << m) - 1) {
    memset(tbl, -1, sizeof(tbl));
    cout << dynamic(all, 0) << endl;
  } else cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

typedef long long LL;

struct F {
  int x, k, m;
};

int n, m;
LL b;
F f[100];
LL tbl[(1 << 20)][100];

bool cmp(const F &f1, const F &f2) {
  return f1.k < f2.k;
}

LL dynamic(int problems, int frend) {
  LL &r = tbl[problems][frend];
  if (r != -1) return r;

  int common = f[frend].m & problems;
  int nproblems = problems ^ common;

  if (!nproblems) return r = f[frend].x;

  r = -2;
  for (int i = 0; i < frend; ++i) {
    if (f[i].m & nproblems) {
      LL bare_cost = dynamic(nproblems, i);
      if (bare_cost != -2 && (r == -2 || (r > bare_cost + f[frend].x))) {
    r = bare_cost + f[frend].x;
      }
    }
  }
  return r;
}

int main() {
  cin >> n >> m >> b;
  memset(tbl, -1, sizeof(tbl));
  for (int i = 0; i < n; ++i) {
    int mi, mii;
    f[i].m = 0;
    cin >> f[i].x >> f[i].k >> mi;
    for (int j = 0; j < mi; ++j) {
      cin >> mii;
      --mii;
      f[i].m |= (1 << mii);
    }
  }
  sort(f, f + n, cmp);

  int all_problems = (1 << m) - 1;
  LL min_cost = -1;
  for (int i = 0; i < n; ++i) {
    LL mon_cost = b * f[i].k;
    LL cost = dynamic(all_problems, i);
    if (cost != -2 && (min_cost == -1 || min_cost > cost + mon_cost)) {
      min_cost = cost + mon_cost;
    }
  }
  cout << min_cost << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

typedef long long LL;

struct P {
  int probs, money, mons;
};

int n, m, all;
P ps[101];
LL tbl[1 << 21];
LL b;

LL dynamic(int mask, int mcount) {
  LL &r = tbl[mask];
  if (r != -1) return r;
  if (!mask) return r = 0;

  r = -1;
  for (int i = 0; i < n; ++i) {
    if (mask & ps[i].probs) {
      int nmcount = ps[i].mons > mcount ? ps[i].mons : mcount;
      LL diff = ps[i].mons > mcount ? ps[i].mons - mcount : 0;
      LL tmp = dynamic(mask & ~ps[i].probs, nmcount);
      tmp += ps[i].money + diff * b;
      if (r == -1 || r > tmp) {
	r = tmp;
      }
    }
  }
  return r;
}

bool cmp(const P &a, const P &b) {
  return a.mons < b.mons;
}

int main() {
  all = 0;
  cin >> n >> m >> b;
  for (int i = 0; i < n; ++i) {
    int mi, mip;
    cin >> ps[i].money >> ps[i].mons >> mi;
    ps[i].probs = 0;
    for (int j = 0; j < mi; ++j) {
      cin >> mip;
      --mip;
      ps[i].probs |= (1 << mip);
      all |= (1 << mip);
    }
  }
  sort(ps, ps + n, cmp);
  if (all == (1 << m) - 1) {
    memset(tbl, -1, sizeof(tbl));
    cout << dynamic(all, 0) << endl;
  } else cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

typedef long long LL;

struct F {
  int x, k, m;
};

int n, m;
LL b;
F f[100];
LL tbl[(1 << 20)];

bool cmp(const F &f1, const F &f2) {
  return f1.k < f2.k;
}

LL dynamic(int problems, int frend) {
  LL &r = tbl[problems];
  if (r != -1) return r;

  int common = f[frend].m & problems;
  int nproblems = problems ^ common;

  if (!nproblems) return r = f[frend].x;

  r = -2;
  for (int i = 0; i < frend; ++i) {
    if (f[i].m & nproblems) {
      LL bare_cost = dynamic(nproblems, i);
      if (bare_cost != -2 && (r == -2 || (r > bare_cost + f[frend].x))) {
    r = bare_cost + f[frend].x;
      }
    }
  }
  return r;
}

int main() {
  cin >> n >> m >> b;

  for (int i = 0; i < n; ++i) {
    int mi, mii;
    f[i].m = 0;
    cin >> f[i].x >> f[i].k >> mi;
    for (int j = 0; j < mi; ++j) {
      cin >> mii;
      --mii;
      f[i].m |= (1 << mii);
    }
  }
  sort(f, f + n, cmp);

  int all_problems = (1 << m) - 1;
  LL min_cost = -1;
  for (int i = 0; i < n; ++i) {
    LL mon_cost = b * f[i].k;
    memset(tbl, -1, sizeof(tbl));
    LL cost = dynamic(all_problems, i);
    if (cost != -2 && (min_cost == -1 || min_cost > cost + mon_cost)) {
      min_cost = cost + mon_cost;
    }
  }
  cout << min_cost << endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const long long MAX=1000000000000000000;
struct node{
	LL x;
	int k,a;
}v[110];
int n,m,x,y;
LL b,f[2000010],ans;
bool comp(node x,node y)
{
	return x.k<y.k;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%d%d",&v[i].x,&v[i].k,&x);
		for (int j=1;j<=x;j++)
		 {
		 	scanf("%d",&y);
		 	v[i].a|=(1<<(y-1));
		 }
	}
	sort(v+1,v+n+1,comp);
	int len=(1<<(m))-1;
	for (int i=1;i<=len;i++) f[i]=MAX;
	f[0]=0;
	ans=MAX;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=0;j<len;j++)
	 	 if (f[j|v[i].a]>f[j]+v[i].x) f[j|v[i].a]=f[j]+v[i].x;
	 	ans=min(ans,f[len]+(LL)v[i].k*b);
	 }
	if (ans==MAX)
	{
		printf("%d\n",-1);
	 }
	 else
	  printf("%lld\n",ans);
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const long long MAX=100000000000000;
struct node{
	LL x;
	int k,a;
}v[110];
int n,m,x,y;
LL b,f[2000010],ans;
bool comp(node x,node y)
{
	return x.k<y.k;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%d%d",&v[i].x,&v[i].k,&x);
		for (int j=1;j<=x;j++)
		 {
		 	scanf("%d",&y);
		 	v[i].a|=(1<<(y-1));
		 }
	}
	sort(v+1,v+n+1,comp);
	int len=(1<<(m))-1;
	for (int i=1;i<=len;i++) f[i]=MAX;
	f[0]=0;
	ans=MAX;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=0;j<len;j++)
	 	 if (f[j|v[i].a]>f[j]+v[i].x) f[j|v[i].a]=f[j]+v[i].x;
	 	ans=min(ans,f[len]+(LL)v[i].k*b);
	 }
	if (ans==MAX)
	{
		printf("%d\n",-1);
	 }
	 else
	  printf("%lld\n",ans);
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const long long MAX=1000000000000000010;
struct node{
	LL x;
	int k,a;
}v[110];
int n,m,x,y;
LL b,f[2000010],ans;
bool comp(node x,node y)
{
	return x.k<y.k;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%d%d",&v[i].x,&v[i].k,&x);
		for (int j=1;j<=x;j++)
		 {
		 	scanf("%d",&y);
		 	v[i].a|=(1<<(y-1));
		 }
	}
	sort(v+1,v+n+1,comp);
	int len=(1<<(m))-1;
	for (int i=1;i<=len;i++) f[i]=MAX;
	f[0]=0;
	ans=MAX;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=0;j<len;j++)
	 	 if (f[j|v[i].a]>f[j]+v[i].x) f[j|v[i].a]=f[j]+v[i].x;
	 	ans=min(ans,f[len]+(LL)v[i].k*b);
	 }
	if (ans==MAX)
	{
		printf("%d\n",-1);
	 }
	 else
	  printf("%lld\n",ans);
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const long long MAX=2000000000000000000;
struct node{
	LL x;
	int k,a;
}v[110];
int n,m,x,y;
LL b,f[2000010],ans;
bool comp(node x,node y)
{
	return x.k<y.k;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%d%d",&v[i].x,&v[i].k,&x);
		for (int j=1;j<=x;j++)
		 {
		 	scanf("%d",&y);
		 	v[i].a|=(1<<(y-1));
		 }
	}
	sort(v+1,v+n+1,comp);
	int len=(1<<(m))-1;
	for (int i=1;i<=len;i++) f[i]=MAX;
	f[0]=0;
	ans=MAX;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=0;j<len;j++)
	 	 if (f[j|v[i].a]>f[j]+v[i].x) f[j|v[i].a]=f[j]+v[i].x;
	 	ans=min(ans,f[len]+(LL)v[i].k*b);
	 }
	if (ans==MAX)
	{
		printf("%d\n",-1);
	 }
	 else
	  printf("%lld\n",ans);
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const long long MAX=100000000000000;
struct node{
	LL x;
	int k,a;
}v[110];
int n,m,x,y;
LL b,f[2000010],ans;
bool comp(node x,node y)
{
	return x.k<y.k;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%d%d",&v[i].x,&v[i].k,&x);
		for (int j=1;j<=x;j++)
		 {
		 	scanf("%d",&y);
		 	v[i].a|=(1<<(y-1));
		 }
	}
	sort(v+1,v+n+1,comp);
	int len=(1<<(m))-1;
	for (int i=1;i<=len;i++) f[i]=MAX;
	f[0]=0;
	ans=MAX;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=0;j<len;j++)
	 	 if (f[j|v[i].a]>f[j]+v[i].x) f[j|v[i].a]=f[j]+v[i].x;
	 	ans=min(ans,f[len]+(LL)v[i].k*b);
	 }
	if (ans==MAX)
	{
		printf("%d\n",-1);
	 }
	 else
	  printf("%d\n",ans);
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const LL INF=(LL)1<<62;
LL dp[1<<21];
struct fri
{
    int x,k,cnt;
}a[102];
bool cmp(fri a,fri y)
{
    return a.k<y.k;
}
int main()
{
    int n,m,b;
    while(~scanf("%d%d%d",&n,&m,&b))
    {
        for(int i=0;i<n;i++)
        {
            int num,pos;
            scanf("%d%d%d",&a[i].x,&a[i].k,&num);
            a[i].cnt=0;
            for(int j=0;j<num;j++)
            {
                scanf("%d",&pos);
                --pos;
                a[i].cnt|=(1<<pos);
            }
        }
        sort(a,a+n,cmp);
        for(int i=0;i<(1<<m);i++)
            dp[i]=INF;
        dp[0]=0;
        LL ans=INF;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<(1<<m);j++)
            {
                if(dp[j]>=INF) continue;
                dp[j|a[i].cnt]=min(dp[j|a[i].cnt],dp[j]+a[i].x);
            }
            ans=min(ans,dp[(1<<m)-1]+a[i].k*b);
        }
        printf("%d\n",ans==INF?-1:ans);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
vector<LL>state,monit;
const LL N=20;
LL dp[1<<N];
struct node
{
    LL requr,monitors,num,cnt,pos;
}a[25];
bool cmp(node a,node b)
{
    if(a.pos==b.pos) return a.cnt<b.cnt;
    else return a.pos<b.pos;
}
int main()
{
    LL n,m,b;;
    //n is the number of his friends,m is the number of problems,b is the cost of each monitor;
    while(~scanf("%I64d%I64d%I64d",&n,&m,&b))
    {
        state.clear();
        monit.clear();
        LL tmp,number;
        for(LL i=0; i<(1<<m); i++)
            dp[i]=0x8fffffffffffffff;
        dp[0]=0;
        for(LL i=0; i<n; i++)
        {
            tmp=0;
            scanf("%I64d%I64d%I64d",&a[i].requr,&a[i].monitors,&a[i].num);
            for(LL j=0; j<a[i].num; j++)
            {
                scanf("%I64d",&number);
                tmp+=(1<<(number)-1);
            }
            a[i].pos=tmp;
            a[i].cnt=a[i].requr+a[i].monitors*b;
        }
        sort(a,a+n,cmp);
        for(LL i=0; i<n; i++)
        {
            if(dp[a[i].pos]>a[i].cnt)
            {
                dp[a[i].pos]=min(a[i].cnt,dp[a[i].pos]);
                state.push_back(a[i].pos);
                monit.push_back(a[i].monitors);
            }
        }
        for(LL i=0; i<state.size(); i++)
        {
            for(LL j=0; j<state.size(); j++)
            {
                if((state[i]|state[j])>(1<<m))
                {
                    continue;
                }
                dp[state[i]|state[j]]=min(dp[state[i]|state[j]],dp[state[i]]+dp[state[j]]-min(monit[i],monit[j])*b);
            }
        }
        LL ans=(1<<m)-1;
        if(dp[ans]==0x8fffffffffffffff) printf("-1\n");
        else printf("%I64d\n",dp[ans]);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
vector<LL>state,monit;
const LL N=20;
LL dp[1<<N];
struct node
{
    LL requr,monitors,num,cnt,pos;
}a[25];
bool cmp(node a,node b)
{
    if(a.pos==b.pos) return a.cnt<b.cnt;
    else return a.pos<b.pos;
}
int main()
{
    LL n,m,b;;
    //n is the number of his friends,m is the number of problems,b is the cost of each monitor;
    while(~scanf("%I64d%I64d%I64d",&n,&m,&b))
    {
        state.clear();
        LL tmp,number;
        for(LL i=0; i<(1<<m); i++)
            dp[i]=0xffffffffffffffff;
        dp[0]=0;
        for(LL i=0; i<n; i++)
        {
            tmp=0;
            scanf("%I64d%I64d%I64d",&a[i].requr,&a[i].monitors,&a[i].num);
            for(LL j=0; j<a[i].num; j++)
            {
                scanf("%I64d",&number);
                tmp+=(1<<(number)-1);
            }
            a[i].pos=tmp;
            a[i].cnt=a[i].requr+a[i].monitors*b;
        }
        sort(a,a+n,cmp);
        for(LL i=0; i<n; i++)
        {
            if(dp[a[i].pos]>a[i].cnt)
            {
                dp[a[i].pos]=min(a[i].cnt,dp[a[i].pos]);
                state.push_back(a[i].pos);
                monit.push_back(a[i].monitors);
            }
        }
        bool flag=1;
        for(LL i=0; i<state.size(); i++)
        {
            for(LL j=0; j<state.size(); j++)
            {
                if((state[i]|state[j])>(1<<m))
                {
                    continue;
                }
                dp[state[i]|state[j]]=min(dp[state[i]|state[j]],dp[state[i]]+dp[state[j]]-min(monit[i],monit[j])*b);
                if((state[i]|state[j])==(1<<m)-1)
                {
                    flag=0;
                }
            }
        }
        LL ans=(1<<m)-1;
        if(flag) printf("-1\n");
        else printf("%I64d\n",dp[ans]);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
vector<LL>state,monit;
const LL N=20;
LL dp[1<<N];
struct node
{
    LL requr,monitors,num,cnt,pos;
}a[25];
bool cmp(node a,node b)
{
    if(a.pos==b.pos) return a.cnt<b.cnt;
    else return a.pos<b.pos;
}
int main()
{
    LL n,m,b;;
    //n is the number of his friends,m is the number of problems,b is the cost of each monitor;
    while(~scanf("%I64d%I64d%I64d",&n,&m,&b))
    {
        state.clear();
        LL tmp,number;
        for(LL i=0; i<(1<<m); i++)
            dp[i]=0xfffffffffff;
        dp[0]=0;
        for(LL i=0; i<n; i++)
        {
            tmp=0;
            scanf("%I64d%I64d%I64d",&a[i].requr,&a[i].monitors,&a[i].num);
            for(LL j=0; j<a[i].num; j++)
            {
                scanf("%I64d",&number);
                tmp+=(1<<(number)-1);
            }
            a[i].pos=tmp;
            a[i].cnt=a[i].requr+a[i].monitors*b;
        }
        sort(a,a+n,cmp);
        for(LL i=0; i<n; i++)
        {
            if(dp[a[i].pos]>a[i].cnt)
            {
                dp[a[i].pos]=min(a[i].cnt,dp[a[i].pos]);
                state.push_back(a[i].pos);
                monit.push_back(a[i].monitors);
            }
        }
        for(LL i=0; i<state.size(); i++)
        {
            for(LL j=0; j<state.size(); j++)
            {
                if((state[i]|state[j])>(1<<m))
                {
                    continue;
                }
                dp[state[i]|state[j]]=min(dp[state[i]|state[j]],dp[state[i]]+dp[state[j]]-min(monit[i],monit[j])*b);
            }
        }
        LL ans=(1<<m)-1;
        if(dp[ans]==0xfffffffffff) printf("-1\n");
        else printf("%I64d\n",dp[ans]);
    }
    return 0;
}