#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;){
            if(s[y] != S[i]){
                if(y != 0)y=kmp[y-1];
                if(v[x][r].e - i + y < s.size() && v[x].size() == 0) break;
                i++;
            }
            if(s[y] == S[i]){
                y++;
                i++;
            }
            if(y == s.size()){
                ans++;
                if(y != 0)y=kmp[y-1];
                else i++;
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
            ++i;
        }
        else{
            if(j != 0)j=kmp[j-1];
            else i++;
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;i++){
            while (s[y] != S[i] && y > 0){
                y=kmp[y-1];
            }
            if (s[y] == S[i])
                y++;
            if(y == s.size()){
                ans++;
                y=kmp[y-1];
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
            ++i;
        }
        else{
            if(j != 0)j=kmp[j-1];
            else i++;
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;i++){
            if(s[y] != S[i]){
                if(y != 0)y=kmp[y-1];
            }
            if(s[y] == S[i]){
                y++;
            }
            if(y == s.size()){
                ans++;
                if(y != 0)y=kmp[y-1];
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();i++){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
        }
        else{
            if(j != 0)j=kmp[j-1];
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;){
            if(s[y] != S[i]){
                if(y != 0)y=kmp[y-1];
                if(v[x][i].e - i + y < s.size() && v[x].size() == 0) break;
                else i++;
            }
            if(s[y] == S[i]){
                y++;
                i++;
            }
            if(y == s.size()){
                ans++;
                if(y != 0)y=kmp[y-1];
                else i++;
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
            ++i;
        }
        else{
            if(j != 0)j=kmp[j-1];
            else i++;
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;i++){
            if(s[y] != S[i]){
                if(y != 0)y=kmp[y-1];
                if(v[x][r].e - i + y < s.size() && v[x].size() == 0) break;
            }
            if(s[y] == S[i]){
                y++;
            }
            if(y == s.size()){
                ans++;
                if(y != 0)y=kmp[y-1];
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();i++){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
        }
        else{
            if(j != 0)j=kmp[j-1];
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct st{
  long long q;
  long long w;
  long long e;
};
st str;
vector<st>v[2000001];
string s,t,S;
long long kmp[2000001];
long long n,i,ans,a;
void dfs(int x,int y){
    int k=y;
    for(int r=0;r<v[x].size();r++){
        int y=k;
        for(int i=v[x][r].w;i<v[x][r].e;i++){
            while (s[y] != S[i] && y > 0){
                y=kmp[y-1];
                if(v[x][r].e - i + y < s.size() && v[v[x][r].q].size() == 0) break;
            }
            if (s[y] == S[i])
                y++;
            if(y == s.size()){
                ans++;
                y=kmp[y-1];
            }
        }
        dfs(v[x][r].q,y);
    }
}
main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>a>>t;
        str.w=S.size();
        S=S+t;
        str.q=i;
        str.e=S.size();
        v[a].push_back(str);
    }
    cin>>s;
    int j=0;
    for(int i=1;i<s.size();i++){
        if(j == s.size() - 1)break;
        if(s[i] == s[j]){
            kmp[i]=++j;
        }
        else{
            if(j != 0)j=kmp[j-1];
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ld long double
#define forr(i,k,n) for(ll i=k;i<n;i++)
#define rev(i,k) for(ll i=k;i>=0;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pll pair<ll,ll>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
int main(){

        ll t;
        cin>>t;
        while(t--){
            ll n,m;
            cin>>n>>m;
            vector<ll> adj[n+1];
            forr(i,0,m){
                ll u,v;
                cin>>u>>v;
                adj[u].push_back(v);
                adj[v].push_back(u);
            }
            ll ver,max = 0;
            bool visited[n+1];
            forr(i,1,n+1){
                if(adj[i].size()>max){
                    max = adj[i].size();
                    ver = i;
                }
                visited[i] = false;
            }
            queue<ll> q;
            q.push(ver);
            // q.push(-1);
            ll ans = 0;
            vector<ll> ansv;
            while(!q.empty()){
                ll u = q.front();
                visited[u] = true;
                q.pop();
                // if(u==-1){
                //     lev++;
                //     if(!q.empty()){
                //         q.push(-1);
                //     }
                //     continue;
                // }
                bool flag = false;
                for(ll i=0;i<adj[u].size();i++){
                    if(!visited[adj[u][i]]){
                        visited[adj[u][i]] = true;
                        q.push(adj[u][i]);
                      flag = true;
                    }
                }
                if(flag){
                    ansv.push_back(u);
                }
            }
            cout<<ansv.size()<<'\n';
            forr(i,0,min(n/2+1,(ll) ansv.size())){
                cout<<ansv[i]<<" ";
            }
            cout<<'\n';
        }
        return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg, out;
vector<int>vis; int root;
void dfs(int u)
{
	vis[u] = 1; int cnt = 0;
	for (auto v : edg[u])
	{
		if (vis[v])continue;
		cnt++;
		dfs(v);
	}
	if (cnt == 0)
		root = u;
}
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		vis = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		dfs(1);
		fill(all(vis), 0);
		queue<int>q; q.push(root); vis[root] = 1;
		int dis = 1;
		while (!q.empty())
		{
			u = q.front(); q.pop();
			out[dis].push_back(u);
			dis = 1 - dis;
			for (auto x : edg[u])
			{
				if (vis[x])continue;
				vis[x] = 1;
				q.push(x);
			}
		}
		if (out[0].size() > n / 2)swap(out[0], out[1]);
		cout << out[0].size() << finl;
		for (int i = 0; i < out[0].size(); i++)
			cout << out[0][i] << " \n"[i == out[0].size() - 1];
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<set<int>>edg;
vector<int>cnt,out;
int main()
{
	Mohammed_Atef_Hassan;
	int t,n,m,u,v;
	cin >> t;
	while (t--)
	{
		out.clear();
		cin >> n >> m;
		edg = vector<set<int>>(n + 1);
		cnt = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].insert(v);
			edg[v].insert(u);
		}
		set<pair<int, int>>st;
		for (int i = 1; i <=n; i++)
		{
			st.insert({ -(int)edg[i].size(),i });
		}
		while (out.size() < n / 2)
		{
			out.push_back(st.begin()->second);
			for (auto z : edg[st.begin()->second])
			{
				st.erase({ -(int)edg[z].size(),z });
				edg[z].erase(st.begin()->second);
				st.insert({ -(int)edg[z].size(),z });
			}
			st.erase(st.begin());
		}
		cout << out.size() << finl;
		for (int i = 0; i < out.size(); i++)
		{
			cout << out[i] << " \n"[i == out.size() - 1];
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg, out;
vector<int>vis;
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		vis = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		queue<int>q; q.push(1); vis[1] = 1;
		int dis = 1;
		while (!q.empty())
		{
			u = q.front(); q.pop();
			out[dis].push_back(u);
			dis = 1 - dis;
			for (auto x : edg[u])
			{
				if (vis[x])continue;
				vis[x] = 1;
				q.push(x);
			}
		}
		if (out[0].size() > n / 2)swap(out[0], out[1]);
		cout << out[0].size() << finl;
		for (int i = 0; i < out[0].size(); i++)
			cout << out[0][i] << " \n"[i == out[0].size() - 1];
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg,out;
vector<int>vis;
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		vis = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		queue<int>q; q.push(1);
		int dis = 0; vis[1] = 1;
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			out[dis].push_back(p);
			for (auto ch : edg[p])
			{
				if (vis[ch])continue;
				vis[ch] = 1;
				q.push(ch);
			}
			dis=1-dis;
		}
		if (out[0].size() > n / 2)swap(out[0], out[1]);
		cout << out[0].size() << finl;
		for (int i = 0; i < out[0].size(); i++)
		{
			cout << out[0][i] << " \n"[i == out[0].size() - 1];
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg,out;
vector<int>vis;
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		vis = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		queue<int>q; q.push(1);
		int dis = 0;
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			out[dis].push_back(p);
			for (auto ch : edg[p])
			{
				if (vis[ch])continue;
				vis[ch] = 1;
				q.push(ch);
			}
			dis=1-dis;
		}
		if (out[0].size() > n / 2)swap(out[0], out[1]);
		cout << out[0].size() << finl;
		for (int i = 0; i < out[0].size(); i++)
		{
			cout << out[0][i] << " \n"[i == out[0].size() - 1];
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<set<int>>edg;
vector<int>cnt,out;
int main()
{
	Mohammed_Atef_Hassan;
	int t,n,m,u,v;
	cin >> t;
	while (t--)
	{
		out.clear();
		cin >> n >> m;
		edg = vector<set<int>>(n + 1);
		cnt = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].insert(v);
			edg[v].insert(u);
		}
		set<pair<int, int>>st;
		for (int i = 1; i <=n; i++)
		{
			st.insert({ -(int)edg[i].size(),i });
		}
		while (out.size() < n / 2)
		{
			out.push_back(st.begin()->second);
			for (auto z : edg[st.begin()->second])
			{
				st.erase({ -(int)edg[z].size(),z });
				edg[z].erase(st.begin()->second);
				st.insert({0,z });
			}
			st.erase(st.begin());
		}
		cout << out.size() << finl;
		for (int i = 0; i < out.size(); i++)
		{
			cout << out[i] << " \n"[i == out.size() - 1];
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg, out;
vector<int>level;
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		level = vector<int>(n + 1, INT_MAX);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		level[1] = 0;
		queue<int>q; q.push(1);
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			for (auto ch : edg[p])
			{
				if (level[ch] > level[p] + 1)
				{
					level[ch] = level[p] + 1;
					q.push(ch);
				}
			}
		}
		for (int i = 1; i <= n; i++)
		{
			out[level[i] % 2].push_back(i);
		}
		int s0 = 0, s1 = 0;
		if (out[0].size() <= n / 2)
		{
			s0 = out[0].size(); s1 = n / 2 - s0;
		}
		else
		{
			s1 = out[1].size(); s0 = n / 2 - s1;
		}
		cout << n / 2 << finl;
		for (int i = 0; i < s0; i++)
			cout << out[0][i] << " ";
		for (int i = 0; i < s1; i++)
			cout << out[1][i] << " ";
		cout << finl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
}
vector<vector<int>>edg,out;
vector<int>vis;
int main()
{
	Mohammed_Atef_Hassan
		int t, n, m, u, v;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		edg = vector<vector<int>>(n + 1);
		out = vector<vector<int>>(2);
		vis = vector<int>(n + 1, 0);
		while (m--)
		{
			cin >> u >> v;
			edg[u].push_back(v);
			edg[v].push_back(u);
		}
		queue<int>q; q.push(1);
		int dis = 1; vis[1] = 1;
		while (!q.empty())
		{
			int p = q.front(); q.pop();
			out[dis].push_back(p);
			for (auto ch : edg[p])
			{
				if (vis[ch])continue;
				vis[ch] = 1;
				q.push(ch);
			}
			dis=1-dis;
		}
		if (out[0].size() > n / 2)swap(out[0], out[1]);
		cout << out[0].size() << finl;
		for (int i = 0; i < out[0].size(); i++)
		{
			cout << out[0][i] << " \n"[i == out[0].size() - 1];
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll sl[200001];
vector<ll> an;
void bfs(vector<ll> vc[],ll n){
	ll fl[n+1]={0};
	queue< pair<ll,ll> > qe;
	qe.push({1,1});
	fl[1]=1;

	while(qe.size()>0){
		pair<ll,ll> p=qe.front();
		qe.pop();
		if(p.sc==1){
			sl[p.fs]=1;
			an.ps(p.fs);
		}
		ll i;
		for(i=0;i<vc[p.fs].size();i++){
			if(fl[vc[p.fs][i]]==0){
				fl[vc[p.fs][i]]=1;
				qe.push({vc[p.fs][i],1-p.sc});
			}
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		an.clear();
		memset(sl,0,sizeof(sl));
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		bfs(vc,n);
		for(i=1;i<=n&&an.size()<(n/2);i++){
			if(sl[i]==0){
				an.ps(i);
			}
		}
		cout<<an.size()<<endl;
		for(i=0;i<an.size();i++){
			cout<<an[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;

		vector<ll> an;
		ll sl[200001]={0};
		vector<ll> vc[n+1];
		vector< pair<ll,ll> > pr;
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}
		for(i=1;i<=n;i++){
			pr.ps({vc[i].size(),i});
		}
		sort(all(pr));
		reverse(all(pr));

		for(i=0;i<n&&an.size()<(n/2);i++){
			if(sl[pr[i].sc]==0){
				an.ps(pr[i].sc);
				sl[pr[i].sc]=1;
				for(j=0;j<vc[pr[i].sc].size();j++){
					sl[vc[pr[i].sc][j]]=1;
				}
			}
		}

		cout<<an.size()<<endl;
		for(i=0;i<an.size();i++){
			cout<<an[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll sl[200001];
vector<ll> an;
void bfs(vector<ll> vc[],ll n){
	ll fl[n+1]={0};
	queue< pair<ll,ll> > qe;
	ll st=1,mx=0;
	for(ll i=1;i<=n;i++){
		if(vc[i].size()>mx){
			mx=vc[i].size();
			st=i;
		}
	}
	qe.push({st,1});
	fl[st]=1;

	while(qe.size()>0){
		pair<ll,ll> p=qe.front();
		qe.pop();
		if(p.sc==1){
			sl[p.fs]=1;
			an.ps(p.fs);
		}
		ll i;
		for(i=0;i<vc[p.fs].size();i++){
			if(fl[vc[p.fs][i]]==0){
				fl[vc[p.fs][i]]=1;
				qe.push({vc[p.fs][i],1-p.sc});
			}
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		an.clear();
		memset(sl,0,sizeof(sl));
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		bfs(vc,n);

		cout<<an.size()<<endl;
		for(i=0;i<an.size();i++){
			cout<<an[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
vector<ll> an; ll n,b=0;
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;

	if(mst){
		an.ps(i);
	}
	else b++;
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,m;
		cin>>n>>m;

		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		vector<ll> pr;
		ll fl[n+1];
		for(i=1;i<=n;i++){
			an.clear(); b=0;
			memset(fl,0,sizeof(fl));
			dfs(vc,i,fl,1);
			if(an.size()<=(n/2)&&an.size()+b==n){
				pr=an;
				break;
			}
		}
		cout<<pr.size()<<endl;
		for(i=0;i<pr.size();i++){
			cout<<pr[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
vector<ll> an; ll n,b=0;
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;

	if(mst){
		an.ps(i);
	}
	else b++;
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,m;
		cin>>n>>m;

		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		vector<ll> pr;
		ll fl[n+1];
		for(i=1;i<=n;i++){
			an.clear(); b=0;
			memset(fl,0,sizeof(fl));
			dfs(vc,i,fl,1);
			if(an.size()<=(n/2)&&an.size()+b==n){
				pr=an;
				break;
			}
		}
		if(pr.size()==0) pr.ps(1);
		cout<<pr.size()<<endl;
		for(i=0;i<pr.size();i++){
			cout<<pr[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
vector<ll> an[2]; ll n;
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;

	an[mst].ps(i);
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,m;
		cin>>n>>m;

		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		vector<ll> pr;
		ll fl[n+1]={0};
		dfs(vc,1,fl,1);
		if(an[0].size()<an[1].size()){
			pr=an[0];
		}
		else pr=an[1];

		cout<<pr.size()<<endl;
		for(i=0;i<pr.size();i++){
			cout<<pr[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll cnt[2];
set<ll> an[2];
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;
	an[mst].insert(i);
	for(ll j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		an[0].clear(); an[1].clear();
		cnt[0]=0; cnt[1]=0;
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		dfs(vc,1,fl,0);
		if(an[0].size()<an[1].size()){
			cout<<an[0].size()<<endl;
			for(auto it:an[0]){
				cout<<it<<" ";
			}
		}
		else {
			cout<<an[1].size()<<endl;
			for(auto it:an[1]){
				cout<<it<<" ";
			}
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll cnt[2];
set<ll> an[2];
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;
	an[mst].insert(i);
	for(ll j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		dfs(vc,1,fl,0);
		if(an[0].size()<an[1].size()){
			cout<<an[0].size()<<endl;
			for(auto it:an[0]){
				cout<<it<<" ";
			}
		}
		else {
			cout<<an[1].size()<<endl;
			for(auto it:an[1]){
				cout<<it<<" ";
			}
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

ll n,m;
vector <ll> vec[200005];
vector <ll> an1,an2;
ll vis[200005];

ll solve(ll id,ll c)
{

    if(c==0)
    {
        an1.push_back(id);
    }
    else{
        an2.push_back(id);
    }
    vis[id]=1;
    for(ll i=0;i<vec[id].size();++i)
    {
        ll v = vec[id][i];
        if(vis[v]==-1)solve(v,c^1);
    }

}

int main()
{

    ll q;
    cin>>q;

    while(q--)
    {

        ll n,m;
        cin>>n>>m;
        memset(vis,-1,sizeof(vis));
        an1.clear();an2.clear();
        for(ll i=0;i<=n;i++)vec[i].clear();
        for(ll i=0;i<m;i++)
        {
            ll a,b;
            cin>>a>>b;
            vec[a].push_back(b);
            vec[b].push_back(a);
        }

        solve(1,0);
        //cout<<"YO"<<endl;
        if(an1.size() > an2.size()){
            swap(an1,an2);
        }

        cout<<an1.size()<<endl;
        for(ll i=0;i<an1.size();++i)
        {
            cout<<an1[i]<<" ";
        }cout<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
set<ll> an[2]; ll n;
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;

	an[mst].insert(i);
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,m;
		cin>>n>>m;

		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		set<ll> pr;
		ll fl[n+1]={0};
		dfs(vc,1,fl,1);
		if(an[0].size()<an[1].size()){
			pr=an[0];
		}
		else pr=an[1];

		cout<<pr.size()<<endl;
		for(auto it:pr){
			cout<<it<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n;
	cin>>n;
	ll ar[n];
	for(i=0;i<n;i++){
		cin>>ar[i];
	}

	map<ll,ll> mp;
	mp[4]=0; mp[8]=0; mp[15]=0; mp[16]=0; mp[23]=0; mp[42]=0;

	for(i=0;i<n;i++){
		mp[ar[i]]++;
	}
	ll mn=1e18;
	for(auto it:mp){
		//cout<<it.fs<<" "<<it.sc<<endl;
		mn=min(mn,it.sc);
	}
	mn=6LL*mn;
	ll an=n-mn;
	cout<<an;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
vector<ll> an;
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;
	if(mst){
		an.ps(i);
	}
	ll j;
	for(j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;

		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		vector<ll> pr;
		ll fl[n+1];
		for(i=1;i<=n;i++){
			an.clear();
			memset(fl,0,sizeof(fl));
			dfs(vc,i,fl,1);
			if(an.size()<=(n/2)){
				pr=an;
				break;
			}
		}
		cout<<pr.size()<<endl;
		for(i=0;i<pr.size();i++){
			cout<<pr[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll cnt[2];
vector<ll> an[2];
void dfs(vector<ll> vc[],ll i,ll fl[],ll mst){
	fl[i]=1;
	an[mst].ps(i);
	for(ll j=0;j<vc[i].size();j++){
		if(fl[vc[i][j]]==0){
			dfs(vc,vc[i][j],fl,1-mst);
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		dfs(vc,1,fl,1);
		if(an[0].size()<an[1].size()){
			cout<<an[0].size()<<endl;
			k=an[0].size();
			for(i=0;i<k;i++){
				cout<<an[0][i]<<" ";
			}
		}
		else {
			cout<<an[1].size()<<endl;
			k=an[1].size();
			for(i=0;i<k;i++){
				cout<<an[1][i]<<" ";
			}
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll sl[200001];
vector<ll> an;
void bfs(vector<ll> vc[],ll n){
	ll fl[n+1]={0};
	queue< pair<ll,ll> > qe;
	qe.push({1,1});
	fl[1]=1;

	while(qe.size()>0){
		pair<ll,ll> p=qe.front();
		qe.pop();
		if(p.sc==1){
			sl[p.fs]=1;
			an.ps(p.fs);
		}
		ll i;
		for(i=0;i<vc[p.fs].size();i++){
			if(fl[vc[p.fs][i]]==0){
				fl[vc[p.fs][i]]=1;
				qe.push({vc[p.fs][i],1-p.sc});
			}
		}
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		ll i,j,k,l,n,m;
		cin>>n>>m;
		an.clear();
		memset(sl,0,sizeof(sl));
		vector<ll> vc[n+1];
		for(i=1;i<=m;i++){
			cin>>k>>l;
			vc[k].ps(l);
			vc[l].ps(k);
		}

		ll fl[n+1]={0};
		bfs(vc,n);

		cout<<an.size()<<endl;
		for(i=0;i<an.size();i++){
			cout<<an[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
          par[x].push_back(y);
          parent[y]=x;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(par[i].size()>1)
       {
         color[i]=1;
         k--;
       }
    }
    // cout<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
  //  cout<<parent[4]<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i])color[i]=1,k--;
    }
    cout<<n/2<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       par[i].clear();
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
bool bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
          par[x].push_back(y);
          parent[y]=x;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(par[i].size()>1)
       {
         color[i]=1;
         k--;
       }
    }
    // cout<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
  //  cout<<parent[4]<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i])color[i]=1,k--;
    }
    cout<<n/2<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       par[i].clear();
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002],dist[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    vis[s]=1;
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
find_depth(int s)
{
   queue<int>q;
   vis[s]=1;
   q.push(1);
   dist[s]=0;
   while(q.size())
   {
        int x=q.front();
        q.pop();
        for(int j=0;j<v[x].size();j++)
        {
          int y=v[x][j];
          if(!vis[y])
          {
          dist[y]=dist[x]+1;
          vis[y]=1;
          q.push(y);
          }
        }
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
    }
    find_depth(1);
    int mx=0,s;
    for(int i=1;i<=n;i++)
    {
      if(mx<dist[i]){mx=dist[i];s=i;}
      dist[i]=0;
      vis[i]=0;
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
   // color[s]=1;
    //cout<<parent[2]<<endl;
   // k--;
    for(int i=1;i<=n;i++)
    {
        if(!color[i]&&v[i].size()==1&&!color[parent[i]])
        {
          color[parent[i]]=2;
          k--;
             for(int j=0;j<v[parent[i]].size();j++)
             {
                color[v[parent[i]][j]]=1;
             }
        }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&color[parent[i]]!=2)
      {

        k--;
        if(color[parent[parent[i]]]==2)
        color[i]=2;
        else
          color[parent[i]]=2;
      }
    }
   /**  for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {
        color[i]=1;
        k--;
       }
    }**/
    //cout<<color[9]<<endl;
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i]==2)
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    for(int i=1;i<=n;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {

        color[parent[parent[i]]]=0;
        color[parent[i]]=1;

       }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
          par[x].push_back(y);
          parent[y]=x;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(par[i].size()>1)
       {
         color[i]=1;
         k--;
       }
    }
    // cout<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
  //  cout<<parent[4]<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i])color[i]=1,k--;
    }
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       par[i].clear();
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002],dist[2000002];
find_depth(int s)
{
   queue<int>q;
   vis[s]=1;
   q.push(1);
   dist[s]=0;
   while(q.size())
   {
        int x=q.front();
        q.pop();
        for(int j=0;j<v[x].size();j++)
        {
          int y=v[x][j];
          if(!vis[y])
          {
          dist[y]=dist[x]+1;
          vis[y]=1;
          q.push(y);
          }
        }
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
    }
    find_depth(1);
    set<int>odd,even;
    for(int i=1;i<=n;i++)
    {
      if(dist[i]%2)odd.insert(i);
      else even.insert(i);
      v[i].clear();
      vis[i]=0;
      dist[i]=0;
    }
    if(even.size()<odd.size())
    {
      cout<<even.size()<<"\n";
      for(auto it : even)cout<<it<<" ";
    }
  else
  {
      cout<<odd.size()<<"\n";
      for(auto it : odd)cout<<it<<" ";
   }
    cout<<"\n";

  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    int cnt=1;
    for(int i=1;i<=n;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {
          cnt++;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    /**while(cnt>k){
    for(int i=1;i<=n;i++)
    {
       if(color[i]&&vis[i]&&color[parent[i]])
       {
         color[i]=0;
         cnt--;

       }
    }
  }**/
  k=cnt;
  //  cout<<parent[4]<<endl;
    cout<<k<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    for(int i=1;i<=n;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {
        if(k>0)
        {
          color[parent[i]]=1;
          k--;
        }
        else{
        color[parent[parent[i]]]=0;
        color[parent[i]]=1;
      }

       }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
    // cout<<endl;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       par[i].clear();
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002],dist[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    vis[s]=1;
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
find_depth(int s)
{
   queue<int>q;
   vis[s]=1;
   q.push(1);
   dist[s]=0;
   while(q.size())
   {
        int x=q.front();
        q.pop();
        for(int j=0;j<v[x].size();j++)
        {
          int y=v[x][j];
          if(!vis[y])
          {
          dist[y]=dist[x]+1;
          vis[y]=1;
          q.push(y);
          }
        }
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
    }
    find_depth(1);
    int mx=0,s;
    for(int i=1;i<=n;i++)
    {
      if(mx<dist[i]){mx=dist[i];s=i;}
      dist[i]=0;
      vis[i]=0;
    }
    bfs(s);
     int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=s&&color[i]&&color[parent[i]])
        {
            color[i]=0;
            k++;
        }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {
        color[i]=1;
        k--;
       }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    int cnt=1;
    for(int i=1;i<=n;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {
          cnt++;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    if(cnt>k){
    for(int i=1;i<=n&&cnt>k;i++)
    {
       if(color[i]&&vis[i]&&color[parent[i]])
       {
         color[i]=0;
         cnt--;

       }
    }
  }
  k=cnt;
  //  cout<<parent[4]<<endl;
    cout<<k<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 30-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002],dist[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    vis[s]=1;
    parent[s]=s;
    while(q.size())
    {
       int x=q.front();
       vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
find_depth(int s)
{
   queue<int>q;
   vis[s]=1;
   q.push(1);
   dist[s]=0;
   while(q.size())
   {
        int x=q.front();
        q.pop();
        for(int j=0;j<v[x].size();j++)
        {
          int y=v[x][j];
          if(!vis[y])
          {
          dist[y]=dist[x]+1;
          vis[y]=1;
          q.push(y);
          }
        }
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
    }
    find_depth(1);
    int mx=0,s;
    for(int i=1;i<=n;i++)
    {
      if(mx<dist[i]){mx=dist[i];s=i;}
      dist[i]=0;
      vis[i]=0;
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
   // color[s]=1;
    //cout<<parent[2]<<endl;
   // k--;
    for(int i=1;i<=n;i++)
    {
        if(!color[i]&&v[i].size()==1&&!color[parent[i]])
        {
          color[parent[i]]=2;
          k--;
             for(int j=0;j<v[parent[i]].size();j++)
             {
                color[v[parent[i]][j]]=1;
             }
        }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&color[parent[i]]!=2)
      {

        k--;
        if(color[parent[parent[i]]]==2)
        color[i]=2;
        else
          color[parent[i]]=2;
      }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]]!=2)
       {
        color[i]=2;
        k--;
       }
    }
    //cout<<color[9]<<endl;
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i]==2)
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=s&&color[i]&&color[parent[i]])
        {
            color[i]=0;
            k++;
        }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {
        color[i]=1;
        k--;
       }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


/**
     **author : _KMS_
     **created : 29-04-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000007;
typedef long long ll;
vector<int>v[200002],par[200002];
bool vis[200002];
int color[2000002],parent[2000002];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    parent[s]=s;
    vis[s]=1;
    while(q.size())
    {
       int x=q.front();
       //vis[x]=1;
       q.pop();
       for(int j=0;j<v[x].size();j++)
       {
        int y=v[x][j];
        if(!vis[y])
        {
          q.push(y);
         // par[x].push_back(y);
          parent[y]=x;
          vis[y]=1;
        }
       }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int d=0,s=1;
    for(int i=0;i<m;i++)
    {
         int x,y;
         cin>>x>>y;
         v[x].push_back(y);
         v[y].push_back(x);
         if(v[x].size()>d){s=x;d=v[x].size();}
         if(v[y].size()>d){s=y;d=v[y].size();}
    }
    bfs(s);
    int k=n/2;
   // cout<<s<<endl;
    // cout<<endl;
    color[s]=1;
    //cout<<parent[2]<<endl;
    k--;
    for(int i=1;i<=n&&k>0;i++)
    {
      if(vis[i]&&!color[i]&&!color[parent[i]])
      {

        k--;
        if(color[parent[parent[i]]])
        color[i]=1;
        else
          color[parent[i]]=1;
      }
    }
    for(int i=1;i<=n&&k>0;i++)
    {
       if(!color[i]&&vis[i]&&!color[parent[i]])
       {
        color[i]=1;
        k--;
       }
    }
  //  cout<<parent[4]<<endl;
    cout<<((n/2)-k)<<"\n";
    for(int i=1;i<=n;i++)
    {
       if(color[i])
       {
        cout<<i<<" ";
       }
       color[i]=0;
       v[i].clear();
       parent[i]=0;
       vis[i]=0;
    }
    cout<<"\n";
  }

    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[3];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){

if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    ++test_case;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =0 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[0].size() <  ans[1].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

    dfs(1 , 0 );

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[2];
int colr[N];
int test_case=0;

void dfs(int u, int c){
	if(vis[u] == test_case)
		return;
	vis[u] = test_case;
	ans[c].push_back(u);
	for(auto &it:grph[u])
		dfs(it, c ^ 1);
}
int n ,m ;

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    test_case++;
   ans[0].clear();
		ans[1].clear();
		cin >> n >> m;
		for(int i = 1; i <= n; i++)
			grph[i].clear();
		for(int i = 1; i <= m; i++)
		{
			int u, v;
			cin >> u >> v;
			grph[u].push_back(v);
			grph[v].push_back(u);
		}
		dfs(1, 0);
		if(ans[1].size() < ans[0].size())
			swap(ans[0], ans[1]);
		cout << ans[0].size() << endl;
		for(auto &it:ans[0])
			cout << it << " ";
		cout << endl;

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[3];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){

if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    ++test_case;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =0 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[1].size() <  ans[0].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[2];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){
if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    test_case++;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =1 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[1].size() <  ans[0].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[2];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){
if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    test_case++;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =1 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[1].size() <  ans[0].size())
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[3];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){

if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    ++test_case;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =0 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[0].size() <  ans[1].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[3];
int colr[N];
int test_case=0;

void dfs( int node ,int c ){

if(vis[node]==test_case) return ;
ans[c].push_back(node);
vis[node] =  test_case;
for(auto next : grph[node])
    dfs( next , c^1);

}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    ++test_case;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =0 ; i<N ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[1].size() <  ans[0].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include"bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;

int vis[N];
vector<int> grph[N];
vector<int>ans[2];
int colr[N];
int test_case=0;

void dfs(int u, int c){
	if(vis[u] == test_case)
		return;
	vis[u] = test_case;
	ans[c].push_back(u);
	for(auto &it:grph[u])
		dfs(it, c ^ 1);
}

int main( void ){
int t ;
scanf("%d",&t);
while(t--){
    test_case++;
    int n  ,a, b , m ;
    scanf("%d%d",&n,&m);
    ans[0].clear();
    ans[1].clear();
    for(int i =1 ; i<=n ; ++i ) grph[i].clear();

    for(int i =1 ; i<=m ; ++i ){
        scanf("%d%d",&a,&b);
        grph[a].push_back(b);
        grph[b].push_back(a);
    }
    dfs(1 , 0 );
    if ( ans[1].size() <  ans[0].size());
        swap( ans[0] , ans[1]);

    printf("%d\n",ans[0].size());

    for(auto &it : ans[0])
        cout<<it<<" ";
    printf("\n");

}

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
typedef vector<int > VI;
typedef vector<VI> VII;
int f[maxn];
int ans[2];
vector<int > a[2];
void dfs(int node,int p,VII &d,VII &a)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].emplace_back(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p,d,a);
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        VII d,a;
        a.resize(2);
        d.resize(n+1);
        memset(f,0,sizeof(f[0]*(n+1)) );

        int x,y;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].emplace_back(y);
            d[y].emplace_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1,d,a);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            printf("%d\n",ans[0]);
            for(int i=0;i<a[0].size();i++)
                printf("%d ",a[0][i]);
        }
        else
        {
            printf("%d\n",ans[1]);
            for(int i=0;i<a[1].size();i++)
                printf("%d ",a[1][i]);
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
vector<int > d[maxn];
int f[maxn];
int ans[2];
stack<int > a[2];
void dfs(int node,int p)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].push(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p);
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            d[i].clear();
        memset(f,0,sizeof(f));
        int x,y;

        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].push_back(y);
            d[y].push_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            cout<<ans[0]<<endl;
            while(!a[0].empty())
            {
                cout<<a[0].top()<<' ';
                a[0].pop();
            }
        }
        else
        {
            cout<<ans[1]<<endl;
            while(!a[1].empty())
            {
                cout<<a[1].top()<<' ';
                a[1].pop();
            }
        }
        while(!a[0].empty()) a[0].pop();
        while(!a[1].empty()) a[1].pop();
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
typedef vector<int > VI;
typedef vector<VI> VII;
int f[maxn];
int ans[2];
vector<int > a[2];
void dfs(int node,int p,VII &d,VII &a)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].emplace_back(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p,d,a);
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        VII d,a;
        a.resize(2);
        d.resize(n+1);
        memset(f,0,sizeof(f[0] )*(n+1) );
        //fill(f,0,n+1);
        int x,y;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].emplace_back(y);
            d[y].emplace_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1,d,a);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            printf("%d\n",ans[0]);
            for(int i=0;i<a[0].size();i++)
                printf("%d ",a[0][i]);
        }
        else
        {
            printf("%d\n",ans[1]);
            for(int i=0;i<a[1].size();i++)
                printf("%d ",a[1][i]);
        }
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
vector<int > d[maxn];
int f[maxn];
int ans[2];
vector<int > a[2];
void dfs(int node,int p)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].push_back(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p);
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            d[i].clear();
        memset(f,0,sizeof(f));
        int x,y;

        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].emplace_back(y);
            d[y].emplace_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            cout<<ans[0]<<endl;
            for(int i=0;i<a[0].size();i++)
                cout<<a[0][i]<<' ';
        }
        else
        {
            cout<<ans[1]<<endl;
            for(int i=0;i<a[1].size();i++)
                cout<<a[1][i]<<' ';
        }
        a[0].clear();
        a[1].clear();
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
typedef vector<int > VI;
typedef vector<VI> VII;
int f[maxn];
int ans[2];
vector<int > a[2];
void dfs(int node,int p,VII &d,VII &a)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].emplace_back(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p,d);
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        VII d,a;
        a.resize(2);
        d.resize(n+1);
        memset(f,0,sizeof(f));

        int x,y;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].emplace_back(y);
            d[y].emplace_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1,d,a);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            printf("%d\n",ans[0]);
            for(int i=0;i<a[0].size();i++)
                printf("%d ",a[0][i]);
        }
        else
        {
            printf("%d\n",ans[1]);
            for(int i=0;i<a[1].size();i++)
                printf("%d ",a[1][i]);
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
vector<int > d[maxn];
int f[maxn];
int ans[2];
stack<int > a[2];
void dfs(int node,int p)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].push(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p);
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            d[i].clear();
        memset(f,0,sizeof(f));
        int x,y;

        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].push_back(y);
            d[y].push_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,0);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            cout<<ans[0]<<endl;
            while(!a[0].empty())
            {
                cout<<a[0].top()<<' ';
                a[0].pop();
            }
        }
        else
        {
            cout<<ans[1]<<endl;
            while(!a[1].empty())
            {
                cout<<a[1].top()<<' ';
                a[1].pop();
            }
        }
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
typedef vector<int > VI;
typedef vector<VI> VII;
int f[maxn];
int ans[2];
vector<int > a[2];
void dfs(int node,int p,VII &d)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].push_back(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p,d);
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        VII d;
        d.resize(n+1);

        memset(f,0,sizeof(f));

        int x,y;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].emplace_back(y);
            d[y].emplace_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1,d);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            printf("%d\n",ans[0]);
            for(int i=0;i<a[0].size();i++)
                printf("%d ",a[0][i]);
        }
        else
        {
            printf("%d\n",ans[1]);
            for(int i=0;i<a[1].size();i++)
                printf("%d ",a[1][i]);
        }
        a[0].clear();
        a[1].clear();
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
vector<int > d[maxn];
int f[maxn];
int ans[2];
stack<int > a[2];
void dfs(int node,int p)
{
    if(f[node]) return ;
    f[node]=1;
    a[p].push(node);
    ans[p]++;
    int son;
    for(int i=0;i<d[node].size();i++)
    {
        son=d[node][i];
        dfs(son,!p);
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            d[i].clear();
        memset(f,0,sizeof(f[0])*(n+1));
        int x,y;

        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            d[x].push_back(y);
            d[y].push_back(x);
        }
        ans[0]=ans[1]=0;
        dfs(1,1);
        //cout<<min(ans[0],ans[1])<<endl;
        if(ans[0]<ans[1])
        {
            cout<<ans[0]<<endl;
            while(!a[0].empty())
            {
                cout<<a[0].top()<<' ';
                a[0].pop();
            }
        }
        else
        {
            cout<<ans[1]<<endl;
            while(!a[1].empty())
            {
                cout<<a[1].top()<<' ';
                a[1].pop();
            }
        }
        while(!a[0].empty()) a[0].pop();
        while(!a[1].empty()) a[1].pop();
        cout<<endl;

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
#define ll int
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
//typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w[2];
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	w[lev].pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev^1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w[0].clear();
		w[1].clear();
		//b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w[0].size()<=n/2)
		{
			cout<<(ll)w[0].size()<<'\n';
			for(auto i : w[0])
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)w[1].size()<<'\n';
			for(auto i : w[1])
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w,b;
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w.clear();
		b.clear();
		vector<ll> g[200004];
		ll lev[200004];
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		queue<ll> q;
		q.push(1);
		lev[1]=0;
		b.pb(1);
		v[1]=1;
		while(!q.empty())
		{
			ll u=q.front();
			q.pop();
			for(auto i : g[u])
			{
				if(v[i] == 0)
				{
					v[i]=1;
					q.push(i);
					lev[i]=lev[u]+1;
					if(lev[i]&1)
					w.pb(i);
					else
					b.pb(i);
				}
			}
		}
		if((ll)w.size()<=n/2)
		{
			cout<<(ll)w.size()<<'\n';
			for(auto i : w)
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)b.size()<<'\n';
			for(auto i : b)
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
#define ll int
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
//typedef long long ll;
//typedef long double lf;
ll n,m;
bool v[200004];
vector<ll> w[2];
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	w[lev].pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev^1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w[0].clear();
		w[1].clear();
		//b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w[0].size()<=n/2)
		{
			cout<<(ll)w[0].size()<<'\n';
			for(auto i : w[0])
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)w[1].size()<<'\n';
			for(auto i : w[1])
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w,b;
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	if(lev%2 == 1)
	w.pb(u);
	else
	b.pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev+1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w.clear();
		b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w.size()<=n/2)
		{
			cout<<(ll)w.size()<<'\n';
			for(auto i : w)
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)b.size()<<'\n';
			for(auto i : b)
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w,b;
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	if(lev%2 == 1)
	w.pb(u);
	else
	b.pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev+1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w.clear();
		b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w.size()<=n/2)
		{
			cout<<(ll)w.size()<<'\n';
			for(auto i : w)
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)b.size()<<'\n';
			for(auto i : b)
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
#define ll int
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
//typedef long long ll;
//typedef long double lf;
ll n,m,v[200004];
vector<ll> w[2];
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	w[lev].pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev^1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w[0].clear();
		w[1].clear();
		//b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w[0].size()<=n/2)
		{
			cout<<(ll)w[0].size()<<'\n';
			for(auto i : w[0])
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)w[1].size()<<'\n';
			for(auto i : w[1])
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w,b;
void dfs(ll u,ll lev,vector<ll> (&g)[200004])
{
	v[u]=1;
	if(lev&1)
	w.pb(u);
	else
	b.pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev+1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w.clear();
		b.clear();
		vector<ll> g[200004];
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w.size()<=n/2)
		{
			cout<<(ll)w.size()<<'\n';
			for(auto i : w)
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)b.size()<<'\n';
			for(auto i : b)
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w[2];
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	w[lev].pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev^1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w[0].clear();
		w[1].clear();
		//b.clear();
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		vector<ll> g[n+4];
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w[0].size()<=n/2)
		{
			cout<<(ll)w[0].size()<<'\n';
			for(auto i : w[0])
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)w[1].size()<<'\n';
			for(auto i : w[1])
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fs first
#define se second
#define mp make_pair
#define pb push_back
#define precise(n,k) fixed<<setprecision(k)<<n
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef long long ll;
typedef long double lf;
ll n,m,v[200004];
vector<ll> w,b;
void dfs(ll u,ll lev,vector<ll> g[])
{
	v[u]=1;
	if(lev&1)
	w.pb(u);
	else
	b.pb(u);
	for(auto i : g[u])
	{
		if(v[i] == 0)
		dfs(i,lev+1,g);
	}
}
int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		memset(v,0,sizeof(v));
		w.clear();
		b.clear();
		vector<ll> g[200004];
		//for(ll i=0;i<200004;i++)
		//g[i].clear();
		cin>>n>>m;
		for(ll i=0;i<m;i++)
		{
			ll u,v;
			cin>>u>>v;
			g[u].pb(v);
			g[v].pb(u);
		}
		dfs(1,0,g);
		if((ll)w.size()<=n/2)
		{
			cout<<(ll)w.size()<<'\n';
			for(auto i : w)
			cout<<i<<' ';
			cout<<'\n';
		}
		else
		{
			cout<<(ll)b.size()<<'\n';
			for(auto i : b)
			cout<<i<<' ';
			cout<<'\n';
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    priority_queue < pair<int, int> > p, q;
    rep( i, 0, n){
      p.push({size(G[i]), i});
    }
    vector< bool > vis(n, false);
    set<ll> ansv;

    while( !p.empty()){
      ii x = p.top(); p.pop();
      if( vis [ x.S] ) {
        q.push(x);continue;
      }
      vis[x.S] = true;
      rep( j , 0, size(G[x.S])) vis[G[x.S][j]] = true;
      ansv.insert( x.S );
    }

    cout << size(ansv) << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}