import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {

	static class Task {

		int NN = 200005;
		int MOD = 1000000007;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		List<Integer> [] g;
		boolean [] vis;
		int [] cnt;

		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-->0) {
				int n = in.nextInt();
				int m= in.nextInt();
				g = new ArrayList[n + 1];
				vis = new boolean [n + 1];
				cnt = new int[n + 1];
				for(int i=1;i<=n;++i) {
					g[i] = new ArrayList<>();
					vis[i] = false;
					cnt[i] = 0;
				}
				for(int i=1;i<=m;++i) {
					int u = in.nextInt();
					int v = in.nextInt();
					g[u].add(v);++cnt[u];
					g[v].add(u);++cnt[v];
				}
				TreeSet<Integer> q = new TreeSet<>((u, v) ->
				cnt[u]==cnt[v] ? u.compareTo(v) :
					Integer.valueOf(cnt[v]).compareTo(Integer.valueOf(cnt[u])));
				for(int i=1;i<=n;++i) {
					q.add(i);
				}
				List<Integer> selected = new ArrayList<>();
				while(!q.isEmpty()) {
					int u = q.pollFirst();
					if(vis[u])
						continue;
					vis[u] = true;
					selected.add(u);
					for(int v:g[u]) {
						vis[v] = true;
						q.remove(v);
						for(int w: g[v]) {
							q.remove(w);
							--cnt[w];
							q.add(w);
						}
					}
				}
				out.println(selected.size());
				for(int u: selected) {
					out.print(u + " ");
				}
				out.println();
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

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

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

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

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

    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {

	static class Task {

		int NN = 200005;
		int MOD = 1000000007;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		List<Integer> [] g;
		int [] c;

		void dfs(int x, int col) {
			if(c[x] != -1)
				return;
			c[x] = col;
			for(int y:g[x]) {
				dfs(y, 1 - col);
			}
		}

		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-->0) {
				int n = in.nextInt();
				int m= in.nextInt();
				g = new ArrayList[n + 1];
				c = new int[n + 1];
				for(int i=1;i<=n;++i) {
					g[i] = new ArrayList<>();
					c[i] = -1;
				}
				for(int i=1;i<=m;++i) {
					int u = in.nextInt();
					int v = in.nextInt();
					g[u].add(v);
					g[v].add(u);
				}
				dfs(1, 0);
				int count0 = 0;
				int count1 = 0;
				for(int i=1;i<=n;++i) {
					if(c[i] == 0)++count0;
					else ++count1;
				}
				out.println(Math.min(count0, count1));
				if(count0 < count1) {
					for(int i=1;i<=n;++i) {
						if(c[i] == 0)
							out.print(i + " ");
					}
				} else {
					for(int i=1;i<=n;++i) {
						if(c[i] == 1) {
							out.print(i + " ");
						}
					}
				}
				out.println();
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

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

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

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

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

    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

	static class Task {

		int NN = 200005;
		int MOD = 1000000007;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		List<Integer> [] g;
		boolean [] vis;

		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-->0) {
				int n = in.nextInt();
				int m= in.nextInt();
				g = new ArrayList[n + 1];
				vis = new boolean [n + 1];
				for(int i=1;i<=n;++i) {
					g[i] = new ArrayList<>();
					vis[i] = false;
				}
				for(int i=1;i<=m;++i) {
					int u = in.nextInt();
					int v = in.nextInt();
					g[u].add(v);g[v].add(u);
				}
				List<Integer> nodes = new ArrayList<>();
				for(int i=1;i<=n;++i) {
					nodes.add(i);
				}
				Collections.sort(nodes, (u, v) ->
				Integer.valueOf(g[v].size()).compareTo(Integer.valueOf(g[u].size())));
				List<Integer> selected = new ArrayList<>();
				for(int u: nodes) {
					if(vis[u])
						continue;
					vis[u] = true;
					selected.add(u);
					for(int v:g[u])
						vis[v] = true;
				}
				out.println(selected.size());
				for(int u: selected) {
					out.print(u + " ");
				}
				out.println();
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

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

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

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

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

    }

}


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

public class Main  {

    private static int[] composite;
    public static void main(String[] args) {
        Kattio in = new Kattio(System.in);

        int t = in.nextInt();
        while (t-->0) {
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<Integer>[] g = new ArrayList[n + 1];
            for (int i = 1; i <= n; ++i) g[i] = new ArrayList<>();
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt();
                int v = in.nextInt();

                g[u].add(v);
                g[v].add(u);
            }

            int[] color = new int[n + 1];
            int[] cnt = new int[3];
            dfs(g, 1, 1, color, cnt);

            int min = cnt[1] <= cnt[2] ? 1 : 2;
            in.println(cnt[min]);
            for (int i = 1; i <= n; ++i) {
                if (color[i] == min) {
                    in.print(i + " ");
                }
            } in.println();
        }

        in.close();
    }

    private static void dfs(ArrayList<Integer>[] g, int u, int c, int[] color, int[] cnt) {
        if (color[u] != 0) return;
        color[u] = c;
        cnt[c]++;
        for (int v : g[u]) {
            if (color[v] == 0) {
                dfs(g, v, c == 1 ? 2 : 1, color, cnt);
            }
        }
    }

    static class Kattio extends PrintWriter {
        private BufferedReader r;
        private String line;
        private StringTokenizer st;
        private String token;

        public Kattio(InputStream i) {
            super(new BufferedOutputStream(System.out));
            r = new BufferedReader(new InputStreamReader(i));
        }

        public Kattio(InputStream i, OutputStream o) {
            super(new BufferedOutputStream(o));
            r = new BufferedReader(new InputStreamReader(i));
        }

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

        private String peekToken() {
            if (token == null)
                try {
                    while (st == null || !st.hasMoreTokens()) {
                        line = r.readLine();
                        if (line == null) return null;
                        st = new StringTokenizer(line);
                    }
                    token = st.nextToken();
                } catch (IOException e) {
                }
            return token;
        }

        private String nextToken() {
            String ans = peekToken();
            token = null;
            return ans;
        }

    }
}


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

public class Main  {

    private static int[] composite;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int t = in.nextInt();
        while (t-->0) {
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<Integer>[] g = new ArrayList[n + 1];
            for (int i = 1; i <= n; ++i) g[i] = new ArrayList<>();
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt();
                int v = in.nextInt();

                g[u].add(v);
                g[v].add(u);
            }

            int[] color = new int[n + 1];
            int[] cnt = new int[3];
            dfs(g, 1, 1, color, cnt);

            int min = cnt[1] <= cnt[2] ? 1 : 2;
            System.out.println(cnt[min]);
            for (int i = 1; i <= n; ++i) {
                if (color[i] == min) {
                    System.out.print(i + " ");
                }
            }System.out.println();
        }
    }

    private static void dfs(ArrayList<Integer>[] g, int u, int c, int[] color, int[] cnt) {
        if (color[u] != 0) return;
        color[u] = c;
        cnt[c]++;
        for (int v : g[u]) {
            if (color[v] == 0) {
                dfs(g, v, c == 1 ? 2 : 1, color, cnt);
            }
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashSet;

public class Main
{
	public static void main(String[] args)
	{
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		ArrayList<ArrayList<Integer>> grph =new ArrayList<ArrayList<Integer>>() ;

		HashSet<Integer> hs =new HashSet<Integer>() ,ans =new HashSet<Integer>() ;
		int t =fr.nextInt() ,n ,m ,arr[][] =new int[200000][2] ,i ,u ,v ,ctr ;

		while (t-- > 0) {
			n =fr.nextInt() ;	m =fr.nextInt() ;

			for (i =0 ; i<n ; ++i) {
				grph.add( new ArrayList<Integer>() ) ;	hs.add(i) ;
			}

			for (i =0 ; i<m ; ++i) {
				u =fr.nextInt() - 1 ;	v =fr.nextInt() - 1 ;	grph.get(u).add(v) ;	grph.get(v).add(u) ;
			}
			for (i =0 ; i<n ; ++i) {
				arr[i][0] =i ;	arr[i][1] =grph.get(i).size() ;
			}
			sort (arr , 0 , n-1) ;

			for (i =0 ; i<n ; ++i) {
				ctr =0 ;	if (!hs.contains(arr[i][0]))	continue;

				for (u =0 ; u<grph.get(arr[i][0]).size() ; u++) {
					v =grph.get(arr[i][0]).get(u) ;

					if (hs.contains(v)) {
						++ctr ;	hs.remove(v) ;
					}
				}
				if (ctr > 0) {	ans.add(arr[i][0]) ;	hs.remove(arr[i][0]) ;	}
				if (hs.isEmpty())	break;
			}
			op.println(ans.size()) ;
			for (int j : ans)	op.print((j+1) + " ") ;
			op.println() ;	hs.clear() ;	grph.clear() ;	ans.clear() ;
		}op.flush();	op.close();
	}
	public static void sort(int[][] arr , int l , int u) {
		int m ;

		if(l < u){
			m =(l + u)/2 ;

			sort(arr , l , m);	sort(arr , m + 1 , u);

			merge(arr , l , m , u);
		}
	}
	public static void merge(int[][] arr , int l , int m , int u) {
		int[][] low = new int[m - l + 1][2] ;

		int[][] upr = new int[u - m][2] ;

		int i ,j =0 ,k =0 ;

		for(i =l;i<=m;i++) {
			low[i - l][0] =arr[i][0] ;	low[i - l][1] =arr[i][1] ;
		}

		for(i =m + 1;i<=u;i++) {
			upr[i - m - 1][0] =arr[i][0] ;	upr[i - m - 1][1] =arr[i][1] ;
		}

		i =l;

		while((j < low.length) && (k < upr.length))
		{
			if(low[j][1] > upr[k][1]) {
				arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
			}
			else {
				arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
			}
		}

		while(j < low.length) {
			arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
		}

		while(k < upr.length) {
			arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
		}
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Collections;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		TreeSet<Integer> ts =new TreeSet<>() ;	int dg[] =new int[200001] ,nd[] =new int[200000] ;
 		ArrayList<ArrayList<Integer>> g =new ArrayList<>() ;
 		int t =fr.nextInt() ,n ,m ,i ,j ,k ,l ;	ArrayList<Integer> al =new ArrayList<>() ;
 		ArrayList<HashSet<Integer>> dtn =new ArrayList<>() ;
 		ArrayList<Integer> ans =new ArrayList<>() ;
 		HashSet<Integer> v =new HashSet<>() ;

 		for (i =0 ; i<=200001 ; ++i)	dtn.add(new HashSet<>()) ;

 		while (t-- > 0) {
 	 		n =fr.nextInt() ;	m =fr.nextInt() ;
 	 		for (i =0 ; i<n ; ++i) {
 	 			g.add(new ArrayList<>()) ;	nd[i] =0 ;
 	 		}
 	 		while (m > 0) {
 	 			i =fr.nextInt()-1 ;j =fr.nextInt()-1 ;
 	 			dg[m] =0 ;	dtn.get(m).clear() ;	++nd[i] ;	++nd[j] ;
 	 			g.get(i).add(j) ;	g.get(j).add(i) ;
 	 			--m ;
 	 		}

 	 		for (i =0 ; i<n ; ++i) {
 	 			++dg[nd[i]] ;	ts.add(nd[i]) ;	dtn.get(nd[i]).add(i) ;
 	 		}

 	 		while (v.size()<n) {
 	 			i =ts.last() ;	j =-1 ;
 	 			for (int ky : dtn.get(i)) {
 	 				j =ky ;	break;
 	 			}
 	 			v.add(j) ;	nd[j] =-1 ;	--dg[i] ;	dtn.get(i).remove(j) ;	ans.add(j+1) ;
 	 			if (dg[i]==0)	ts.pollLast() ;	al.clear() ;

 	 			for (k =0 ; k<g.get(j).size() ; ++k) {
 	 				l =g.get(j).get(k) ;	if (nd[l]==-1)	continue;	v.add(l) ;
 	 				al.add(nd[l]) ;	dtn.get(nd[l]).remove(l) ;

 	 				--nd[l] ;	dtn.get(nd[l]).add(l) ;	++dg[nd[l]] ;
 	 				if (dg[nd[l]] == 1)	ts.add(nd[l]) ;
 	 			}
 	 			Collections.sort(al) ;
 	 			for (k =al.size()-1 ; k>-1 ; --k) {
 	 				l =al.get(k) ;	--dg[l] ;	if (dg[l]==0)	ts.remove(l) ;
 	 			}
 	 		}
 	 		op.println(ans.size()) ;
 	 		for (i =0 ; i<ans.size() ; ++i)	op.print(ans.get(i)+" ") ;
 	 		op.println() ;

 			ts.clear() ;g.clear() ;ans.clear() ;v.clear() ;
 		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashSet;

public class Main
{
	public static void main(String[] args)
	{
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		ArrayList<ArrayList<Integer>> grph =new ArrayList<ArrayList<Integer>>() ;

		HashSet<Integer> hs =new HashSet<Integer>() ,ans =new HashSet<Integer>() ;
		int t =fr.nextInt() ,n ,m ,arr[][] =new int[200000][2] ,i ,u ,v ,ctr ;

		while (t-- > 0) {
			n =fr.nextInt() ;	m =fr.nextInt() ;

			for (i =0 ; i<n ; ++i) {
				grph.add( new ArrayList<Integer>() ) ;	hs.add(i) ;
			}

			for (i =0 ; i<m ; ++i) {
				u =fr.nextInt() - 1 ;	v =fr.nextInt() - 1 ;	grph.get(u).add(v) ;	grph.get(v).add(u) ;
			}
			for (i =0 ; i<n ; ++i) {
				arr[i][0] =i ;	arr[i][1] =grph.get(i).size() ;
			}
			sort (arr , 0 , n-1) ;

			for (i =0 ; i<n ; ++i) {
				ctr =0 ;	hs.remove(arr[i][0]) ;
				for (u =0 ; u<grph.get(arr[i][0]).size() ; u++) {
					v =grph.get(arr[i][0]).get(u) ;

					if (hs.contains(v)) {
						++ctr ;	hs.remove(v) ;
					}
				}
				if (ctr > 0)	ans.add(arr[i][0]) ;	if (hs.isEmpty())	break;
			}
			op.println(ans.size()) ;
			for (int j : ans)	op.print((j+1) + " ") ;
			op.println() ;	hs.clear() ;	grph.clear() ;	ans.clear() ;
		}
		op.flush();	op.close();
	}
	public static void sort(int[][] arr , int l , int u) {
		int m ;

		if(l < u){
			m =(l + u)/2 ;

			sort(arr , l , m);	sort(arr , m + 1 , u);

			merge(arr , l , m , u);
		}
	}
	public static void merge(int[][] arr , int l , int m , int u) {
		int[][] low = new int[m - l + 1][2] ;

		int[][] upr = new int[u - m][2] ;

		int i ,j =0 ,k =0 ;

		for(i =l;i<=m;i++) {
			low[i - l][0] =arr[i][0] ;	low[i - l][1] =arr[i][1] ;
		}

		for(i =m + 1;i<=u;i++) {
			upr[i - m - 1][0] =arr[i][0] ;	upr[i - m - 1][1] =arr[i][1] ;
		}

		i =l;

		while((j < low.length) && (k < upr.length))
		{
			if(low[j][1] > upr[k][1]) {
				arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
			}
			else {
				arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
			}
		}

		while(j < low.length) {
			arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
		}

		while(k < upr.length) {
			arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
		}
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st==null || (!st.hasMoreElements()))
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}

			}
			return st.nextToken();
		}
		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Collections;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		TreeSet<Integer> ts =new TreeSet<>() ;	int dg[] =new int[200001] ,nd[] =new int[200000] ;
 		ArrayList<ArrayList<Integer>> g =new ArrayList<>() ;
 		int t =fr.nextInt() ,n ,m ,i ,j ,k ,l ;	ArrayList<Integer> al =new ArrayList<>() ;
 		ArrayList<HashSet<Integer>> dtn =new ArrayList<>() ;
 		ArrayList<Integer> ans =new ArrayList<>() ;
 		HashSet<Integer> v =new HashSet<>() ;

 		for (i =0 ; i<=200001 ; ++i)	dtn.add(new HashSet<>()) ;

 		while (t-- > 0) {
 	 		n =fr.nextInt() ;	m =fr.nextInt() ;
 	 		for (i =0 ; i<n ; ++i) {
 	 			g.add(new ArrayList<>()) ;	nd[i] =0 ;
 	 		}
 	 		while (m-- > 0) {
 	 			i =fr.nextInt()-1 ;j =fr.nextInt()-1 ;
 	 			dg[m] =0 ;	dtn.get(m).clear() ;	++nd[i] ;	++nd[j] ;
 	 			g.get(i).add(j) ;	g.get(j).add(i) ;
 	 		}

 	 		for (i =0 ; i<n ; ++i) {
 	 			++dg[nd[i]] ;	ts.add(nd[i]) ;	dtn.get(nd[i]).add(i) ;
 	 		}

 	 		while (v.size()<n) {
 	 			i =ts.last() ;	j =-1 ;
 	 			for (int ky : dtn.get(i)) {
 	 				j =ky ;	break;
 	 			}
 	 			v.add(j) ;	nd[j] =-1 ;	--dg[i] ;	dtn.get(i).remove(j) ;	ans.add(j+1) ;
 	 			if (dg[i]==0)	ts.pollLast() ;	al.clear() ;

 	 			for (k =0 ; k<g.get(j).size() ; ++k) {
 	 				l =g.get(j).get(k) ;	if (nd[l]==-1)	continue;	v.add(l) ;
 	 				al.add(nd[l]) ;	dtn.get(nd[l]).remove(l) ;

 	 				--nd[l] ;	dtn.get(nd[l]).add(l) ;	++dg[nd[l]] ;
 	 				if (dg[nd[l]] == 1)	ts.add(nd[l]) ;
 	 			}
 	 			Collections.sort(al) ;
 	 			for (k =al.size()-1 ; k>-1 ; --k) {
 	 				l =al.get(k) ;	--dg[l] ;	if (dg[l]==0)	ts.remove(l) ;
 	 			}
 	 		}
 	 		op.println(ans.size()) ;
 	 		for (i =0 ; i<ans.size() ; ++i)	op.print(ans.get(i)+" ") ;
 	 		op.println() ;

 			ts.clear() ;g.clear() ;ans.clear() ;v.clear() ;
 		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;

public class Main
{
	static TreeSet<Integer> ts =new TreeSet<>() ;	static int mrk[] =new int[100000];
	static ArrayList<HashSet<Integer>> g =new ArrayList<>() ;
	static HashMap<Integer,HashSet<Integer>> dtn =new HashMap<>() ;

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		int t =fr.nextInt() ,n ,m ,i ,j =-1 ,k ,ans[] =new int[50000];
		while (t-- > 0) {
			n =fr.nextInt() ;	m =fr.nextInt() ;	k =-1 ;
			for (i =0 ; i<n ; ++i) {
				mrk[i] =0 ;	g.add (new HashSet<Integer>()) ;
			}
			while (m-- > 0) {
				i =fr.nextInt()-1 ;	j =fr.nextInt()-1 ;	++mrk[i] ;	++mrk[j] ;
				g.get(i).add(j) ;	g.get(j).add(i) ;
			}
			for (i =0 ; i<n ; ++i) {
				if (!dtn.containsKey(mrk[i])) {
					dtn.put(mrk[i] , new HashSet<>()) ;	ts.add(mrk[i]) ;
				}
				dtn.get(mrk[i]).add(i) ;
			}
			while (n>0) {
				i =ts.last() ;	--n ;
				for (int ky : dtn.get(i))	{	j =ky ;	break;	}System.out.println(i+" "+j) ;
				ans[++k] =j+1 ;		mrk[j] =-1 ;	dtn.get(i).remove(j) ;
				if (dtn.get(i).isEmpty())	i =ts.pollLast() ;

				for (int l : g.get(j)) {
					if (mrk[l] == -1)	continue ;	--n ;
					dtn.get(mrk[l]).remove(l) ;
					if (dtn.get(mrk[l]).isEmpty())	ts.remove(mrk[l]) ;

					mrk[l] =-1 ;
				}
				for (int l : g.get(j)) {

				}
				for (int o : g.get(l)) {
					if (mrk[o]==-1)	continue;
					dtn.get(mrk[o]).remove(o) ;
					if (dtn.get(mrk[o]).isEmpty())	ts.remove(mrk[o]) ;

					--mrk[o] ;

					if (!dtn.containsKey(mrk[o])) {
						dtn.put(mrk[o] , new HashSet<>()) ;	ts.add(mrk[o]) ;
					}
					dtn.get(mrk[o]).add(o) ;
				}
			}
			op.println(k+1) ;
			while (k>-1)	op.print(ans[k--]+" ") ;	op.println() ;
			g.clear() ;	dtn.clear() ;	ts.clear() ;
		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashSet;

public class Main
{
	public static void main(String[] args)
	{
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		ArrayList<ArrayList<Integer>> grph =new ArrayList<ArrayList<Integer>>() ;

		HashSet<Integer> hs =new HashSet<Integer>() ,ans =new HashSet<Integer>() ;
		int t =fr.nextInt() ,n ,m ,arr[][] =new int[200000][2] ,i ,u ,v ,ctr ;

		while (t-- > 0) {
			n =fr.nextInt() ;	m =fr.nextInt() ;

			for (i =0 ; i<n ; ++i) {
				grph.add( new ArrayList<Integer>() ) ;	hs.add(i) ;
			}

			for (i =0 ; i<m ; ++i) {
				u =fr.nextInt() - 1 ;	v =fr.nextInt() - 1 ;	grph.get(u).add(v) ;	grph.get(v).add(u) ;
			}
			for (i =0 ; i<n ; ++i) {
				arr[i][0] =i ;	arr[i][1] =grph.get(i).size() ;
			}
			sort (arr , 0 , n-1) ;

			for (i =0 ; i<n ; ++i) {
				ctr =0 ;
				for (u =0 ; u<grph.get(arr[i][0]).size() ; u++) {
					v =grph.get(arr[i][0]).get(u) ;

					if (hs.contains(v)) {
						++ctr ;	hs.remove(v) ;
					}
				}
				if (ctr > 0) {	ans.add(arr[i][0]) ;	hs.remove(arr[i][0]) ;	}
				if (hs.isEmpty())	break;
			}
			op.println(ans.size()) ;
			for (int j : ans)	op.print((j+1) + " ") ;
			op.println() ;	hs.clear() ;	grph.clear() ;	ans.clear() ;
		}
		op.flush();	op.close();
	}
	public static void sort(int[][] arr , int l , int u) {
		int m ;

		if(l < u){
			m =(l + u)/2 ;

			sort(arr , l , m);	sort(arr , m + 1 , u);

			merge(arr , l , m , u);
		}
	}
	public static void merge(int[][] arr , int l , int m , int u) {
		int[][] low = new int[m - l + 1][2] ;

		int[][] upr = new int[u - m][2] ;

		int i ,j =0 ,k =0 ;

		for(i =l;i<=m;i++) {
			low[i - l][0] =arr[i][0] ;	low[i - l][1] =arr[i][1] ;
		}

		for(i =m + 1;i<=u;i++) {
			upr[i - m - 1][0] =arr[i][0] ;	upr[i - m - 1][1] =arr[i][1] ;
		}

		i =l;

		while((j < low.length) && (k < upr.length))
		{
			if(low[j][1] > upr[k][1]) {
				arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
			}
			else {
				arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
			}
		}

		while(j < low.length) {
			arr[i][0] =low[j][0] ;	arr[i++][1] =low[j++][1] ;
		}

		while(k < upr.length) {
			arr[i][0] =upr[k][0] ;	arr[i++][1] =upr[k++][1] ;
		}
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Queue;
import java.util.LinkedList;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		ArrayList<ArrayList<Integer>> g =new ArrayList<>() ;
		int t =fr.nextInt() ,n ,m ,i ,j ,k ,lvl[] ;	Queue<Integer> q =new LinkedList<Integer>() ;
		ArrayList<ArrayList<Integer>> ans =new ArrayList<>() ;

 		while (t-- > 0) {
 			n =fr.nextInt() ;	m =fr.nextInt() ;	lvl =new int[n] ;
 			for (i =0 ; i<n ; ++i)	g.add(new ArrayList<>()) ;	ans.add(new ArrayList<>()) ;	ans.add(new ArrayList<>()) ;
 			while (m-- > 0) {
 				i =fr.nextInt()-1 ;	j =fr.nextInt()-1 ;	g.get(i).add(j) ;	g.get(j).add(i) ;
 			}
 			lvl[0] =1 ;	q.add(0) ;
 			while (!q.isEmpty()) {
 				i =q.poll() ;	j =lvl[i]%2 ;	ans.get(j).add(i+1) ;
 				for (j =0 ; j<g.get(i).size() ; ++j) {
 					k =g.get(i).get(j) ;	if (lvl[k]>0)	continue ;
 					lvl[k] =lvl[i]+1 ;	q.add(k) ;
 				}
 			}
 			if (ans.get(0).size() < ans.get(1).size()) {
 				op.println(ans.get(0).size()) ;
 				for (i = 0 ; i<ans.get(0).size() ; ++i)	op.print(ans.get(0).get(i)+" ") ;
 				op.println() ;
 			}
 			else {
 				op.println(ans.get(1).size()) ;
 				for (i = 0 ; i<ans.get(1).size() ; ++i)	op.print(ans.get(1).get(i)+" ") ;
 				op.println() ;
 			}
 			g.clear() ;	q.clear() ;	ans.clear() ;
 		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

		TreeSet<Integer> dg =new TreeSet<>() ;	HashMap<Integer,HashSet<Integer>> dtn =new HashMap<>() ;
		ArrayList<HashSet<Integer>> g =new ArrayList<>() ;	HashSet<Integer> v =new HashSet<>() ,ans =new HashSet<>() ;

		int t =fr.nextInt() ,n ,m ,i ,j ,k ;

		while (t-- > 0) {
			n =fr.nextInt() ;	m =fr.nextInt() ;
			for (i =0 ; i<n ; ++i)	g.add (new HashSet<>()) ;
			while (m-- > 0) {
				i =fr.nextInt()-1 ;	j =fr.nextInt()-1 ;
				g.get(i).add(j) ;	g.get(j).add(i) ;
			}
			for (i =0 ; i<n ; ++i) {
				j =g.get(i).size() ;
				if (!dtn.containsKey(j)) {
					dtn.put(j , new HashSet<>()) ;	dg.add(j) ;
				}
				dtn.get(j).add(i) ;
			}
			while (v.size()<n) {
				while(true) {
					i =dg.last() ;	j =dtn.get(i).size() ;
					if (j==0)	dg.pollLast() ;	else 	break;
				}

				for (int ky : dtn.get(i))	{	j =ky ;	break;	}
				ans.add(j) ;	v.add(j) ;

				for (int ky : g.get(j)) {
					k =g.get(ky).size() ;	v.add(ky) ;	dtn.get(k).remove(ky) ;

					if (!dtn.containsKey(k-1))	dtn.put(k-1,new HashSet<>()) ;

					dtn.get(k-1).add(ky) ;
				}
				dtn.get(i).remove(j) ;
			}
			op.println(ans.size()) ;
			for (int ky : ans)	op.print((ky+1)+" ") ;	op.println() ;

			v.clear() ;	ans.clear() ;	g.clear() ;	dg.clear() ;	dtn.clear() ;
		}
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static ArrayList<Integer> solve(int n){

		boolean flag[]=new boolean[n+1];

		Integer item[]=new Integer[n];
		for(int i=0; i<n; i++)
			item[i]=i+1;
		Arrays.sort(item, (Integer x, Integer y)->{	return adj[y].size()-adj[x].size();	});

		ArrayList<Integer> node=new ArrayList<>();

		for(int k=0; k<n; k++){
			int i=item[k];
			if(!flag[i]){
				node.add(i);
				for(int v: adj[i])
					flag[v]=true;
			}
		}

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			ArrayList<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static HashSet<Integer> solve(int n){

		HashSet<Integer> node=new HashSet<>();
		boolean flag[]=new boolean[n+1];

		Integer value[]=new Integer[n];
		for(int i=0; i<n; i++)
			value[i]=i+1;
		Arrays.sort(value, (Integer x, Integer y)->{	return adj[y].size()-adj[x].size();	});

		for(int k=0; k<n; k++){
			int i=value[k];
			int count=0;
			for(int item: adj[i])
				if(!flag[item])
					count+=1;

			if(count>1){
				flag[i]=true;
				for(int item: adj[i])
					flag[item]=true;
				node.add(i);
			}
		}

		for(int k=0; k<n; k++){
			int i=value[k];
			if(!flag[i]){
				node.add(i);
				for(int item: adj[i])
					flag[item]=true;
			}
		}

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			HashSet<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static ArrayList<Integer> solve(int n){

		ArrayList<Integer> node=new ArrayList<>();
		boolean flag[]=new boolean[n+1];

		Integer value[]=new Integer[n];
		for(int i=0; i<n; i++)
			value[i]=i+1;
		Arrays.sort(value, (Integer x, Integer y)->{	return adj[y].size()-adj[x].size();	});

		for(int k=0; k<n; k++){
			int i=value[k];
			int count=0;
			for(int item: adj[i])
				if(!flag[item])
					count+=1;

			if(count>1){
				flag[i]=true;
				for(int item: adj[i])
					flag[item]=true;
				node.add(i);
			}
		}

		for(int k=0; k<n; k++){
			int i=value[k];
			if(!flag[i]){
				node.add(i);
				for(int item: adj[i])
					flag[item]=true;
			}
		}

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			ArrayList<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static ArrayList<Integer> solve(int n){

		ArrayList<Integer> node=new ArrayList<>();
		boolean flag[]=new boolean[n+1];

		for(int i=1; i<=n; i++){
			int count=0;
			for(int item: adj[i])
				if(!flag[item])
					count+=1;

			if(count>1){
				flag[i]=true;
				for(int item: adj[i])
					flag[item]=true;
				node.add(i);
			}
		}

		for(int i=1; i<=n; i++)
			if(!flag[i]){
				node.add(i);
				for(int item: adj[i])
					flag[item]=true;
			}

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			ArrayList<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static void dfs(int node, HashSet<Integer> set_true, HashSet<Integer> set_false, boolean flag){

		if(set_true.contains(node) || set_false.contains(node))
			return;

		if(flag)
			set_true.add(node);
		else
			set_false.add(node);

		for(int item: adj[node])
			dfs(item, set_true, set_false, !flag);
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			HashSet<Integer> set_true=new HashSet<>();
			HashSet<Integer> set_false=new HashSet<>();

			dfs(1, set_true, set_false, true);

			if(set_true.size()<set_false.size()){
				System.out.println(set_true.size());
				for(int item: set_true)
					System.out.print(item+" ");
			}
			else{
				System.out.println(set_false.size());
				for(int item: set_false)
					System.out.print(item+" ");
			}

			System.out.println();
		}
	}
}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static ArrayList<Integer> solve(int n){

		ArrayList<Integer> node=new ArrayList<>();
		boolean flag[]=new boolean[n+1];

		Integer value[]=new Integer[n];
		for(int i=0; i<n; i++)
			value[i]=i+1;
		Arrays.sort(value, (Integer x, Integer y)->{	return adj[y].size()-adj[x].size();	});

		for(int i=0; i<(n>>1); i++)
			node.add(value[i]);

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			ArrayList<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static ArrayList<Integer> solve(int n){

		boolean flag[]=new boolean[n+1];

		Integer item[]=new Integer[n];
		for(int i=0; i<n; i++)
			item[i]=i+1;
		Arrays.sort(item, (Integer x, Integer y)->{	return adj[y].size()-adj[x].size();	});

		ArrayList<Integer> node=new ArrayList<>();

		for(int k=0; k<n; k++){
			int i=item[k];
			if(!flag[i]){
				int count=0;
				for(int v: adj[i])
					if(!flag[v]){
						flag[v]=true;
						count+=1;
					}
				if(count!=0){
					node.add(i);
					flag[i]=true;
				}
			}
		}

		for(int i=1; i<=n; i++)
			if(!flag[i])
				node.add(i);

		return node;
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			ArrayList<Integer> node=solve(n);
			out.append(node.size()+"\n");
			for(int item: node)
				out.append(item+" ");
			out.append("\n");
		}

		System.out.println(out);

	}

}


import java.util.*;
import java.io.*;
public class Solution1{

	public static Integer INT(String s){
		return Integer.parseInt(s);
	}

	public static Long LONG(String s){
		return Long.parseLong(s);
	}

	//====================================================================================================================

	static LinkedList<Integer> adj[];

	public static void dfs(int node, HashSet<Integer> set_true, HashSet<Integer> set_false, boolean flag){

		if(set_true.contains(node) || set_false.contains(node))
			return;

		if(flag)
			set_true.add(node);
		else
			set_false.add(node);

		for(int item: adj[node])
			dfs(item, set_true, set_false, !flag);
	}

	public static void main(String args[])throws IOException{

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuffer out=new StringBuffer();

		int t=INT(br.readLine());

		while(t--!=0){
			String line[]=br.readLine().split("\\s");
			int n=INT(line[0]),
				m=INT(line[1]);

			adj=new LinkedList[n+1];
			for(int i=0; i<=n; i++)
				adj[i]=new LinkedList<>();

			for(int i=0; i<m; i++){
				line=br.readLine().split("\\s");
				int u=INT(line[0]),
					v=INT(line[1]);

				adj[u].add(v);
				adj[v].add(u);
			}

			HashSet<Integer> set_true=new HashSet<>();
			HashSet<Integer> set_false=new HashSet<>();

			dfs(1, set_true, set_false, true);

			if(set_true.size()<set_false.size()){
				out.append(set_true.size()+"\n");
				for(int item: set_true)
					out.append(item+" ");
			}
			else{
				out.append(set_false.size()+"\n");
				for(int item: set_false)
					out.append(item+" ");
			}

			out.append("\n");
		}
		System.out.print(out);
	}
}


import java.util.* ;
import java.io.* ;
public class CF {

    static Vector<Integer>[] adj ;
    static int[] color ;
    static void dfs(int u , int c){
        color[u] = c ;
        for(int v : adj[u]){
            if(color[v] != -1) continue ;
            dfs(v , c ^ 1) ;
        }
    }
    public static void main(String[] args) throws IOException{
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int t = scn.nextInt() ;
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new Vector[n + 1] ;
            color = new int[n + 1] ;
            for(int i = 1 ; i <= n ; i++){
                adj[i] = new Vector<>() ;
            }
            while(m-- > 0){
                int u = scn.nextInt() , v = scn.nextInt() ;
                adj[u].add(v) ;
                adj[v].add(u) ;
            }
            Arrays.fill(color , -1) ;
            ArrayList<Integer> one = new ArrayList<>() , two = new ArrayList<>() ;
            for(int i = 1 ; i <= n ;i++){
                if(color[i] == -1){
                    dfs(i , 0) ;
                }
            }
            for(int i = 1 ; i <= n ; i++){
                if(color[i] == 0) {
                    one.add(i) ;
                } else {
                    two.add(i) ;
                }
            }
            if(one.size() < two.size()){
                out.write(one.size() + "\n") ;
                for(int x : one){
                    out.write(x + " ");
                }
            } else {
                out.write(two.size() + "\n") ;
                for(int x : two){
                    out.write(x + " ");
                }
            }
            out.write("\n") ;
        }
        out.flush() ;

    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.util.* ;
import java.io.* ;
public class CF {

    static Vector<Integer>[] adj ;
    static int[] color ;
    static void dfs(int u , int c){
        color[u] = c ;
        for(int v : adj[u]){
            if(color[v] != -1) continue ;
            dfs(v , c ^ 1) ;
        }
    }
    public static void main(String[] args) {
        FastReader scn = new FastReader() ;
        int t = scn.nextInt() ;
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new Vector[n + 1] ;
            color = new int[n + 1] ;
            for(int i = 1 ; i <= n ; i++){
                adj[i] = new Vector<>() ;
            }
            while(m-- > 0){
                int u = scn.nextInt() , v = scn.nextInt() ;
                adj[u].add(v) ;
                adj[v].add(u) ;
            }
            Arrays.fill(color , -1) ;
            ArrayList<Integer> one = new ArrayList<>() , two = new ArrayList<>() ;
            for(int i = 1 ; i <= n ;i++){
                if(color[i] == -1){
                    dfs(i , 0) ;
                }
            }
            for(int i = 1 ; i <= n ; i++){
                if(color[i] == 0) {
                    one.add(i) ;
                } else {
                    two.add(i) ;
                }
            }
            if(one.size() < two.size()){
                System.out.println(one.size()) ;
                for(int x : one){
                    System.out.print(x + " ");
                }
            } else {
                System.out.println(two.size()) ;
                for(int x : two){
                    System.out.print(x + " ");
                }
            }
            System.out.println();
        }

    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.util.* ;
import java.io.* ;
public class CF {

    static Vector<Integer>[] adj ;
    static int[] color ;
    static void dfs(int u , int c){
        color[u] = c ;
        for(int v : adj[u]){
            if(color[v] != -1) continue ;
            dfs(v , c ^ 1) ;
        }
    }
    public static void main(String[] args) throws IOException{
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int t = scn.nextInt() ;
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new Vector[n + 1] ;
            color = new int[n + 1] ;
            for(int i = 1 ; i <= n ; i++){
                adj[i] = new Vector<>() ;
            }
            while(m-- > 0){
                int u = scn.nextInt() , v = scn.nextInt() ;
                adj[u].add(v) ;
                adj[v].add(u) ;
            }
            Arrays.fill(color , -1) ;
            ArrayList<Integer> one = new ArrayList<>() , two = new ArrayList<>() ;
            for(int i = 1 ; i <= n ;i++){
                if(color[i] == -1){
                    dfs(i , 0) ;
                }
            }
            for(int i = 1 ; i <= n ; i++){
                if(color[i] == 0) {
                    one.add(i) ;
                } else {
                    two.add(i) ;
                }
            }
            if(one.size() < two.size()){
                System.out.println(one.size()) ;
                for(int x : one){
                    System.out.print(x + " ");
                }
            } else {
                out.write(two.size() + "\n") ;
                for(int x : two){
                    out.write(x + " ");
                }
            }
            out.write("\n") ;
        }
        out.flush() ;

    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

public class CF_1110 {

    static ArrayList<Integer>[] adj ;
    static boolean[] vis ;
    static ArrayList<Integer> al  ;
    static void dfs(int u){
        al.add(u) ;
        for(int v : adj[u]){
            vis[v] = true ;
        }
    }
    public static void main(String[] args) {
        FastReader scn = new FastReader() ;
        int t = scn.nextInt();
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new ArrayList[n + 1]  ;
            for(int i = 1 ; i<= n ; i++){
                adj[i] = new ArrayList<>() ;
            }
            al = new ArrayList<>() ;
            vis = new boolean[n + 1] ;
            while(m-- > 0){
                int x = scn.nextInt() , y = scn.nextInt() ;
                adj[x].add(y) ;
                adj[y].add(x) ;
            }
            for(int i = 1 ; i<= n ;i++){
                if(!vis[i]){
                    dfs(i) ;
                }
            }
            System.out.println(al.size());
            for(int x : al){
                System.out.print(x + " ");
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}


import java.util.* ;
import java.io.* ;
public class CF {

    static Vector<Integer>[] adj ;
    static int[] color ;
    static void dfs(int u , int c){
        color[u] = c ;
        for(int v : adj[u]){
            if(color[v] != -1) continue ;
            dfs(v , c ^ 1) ;
        }
    }
    public static void main(String[] args) {
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int t = scn.nextInt() ;
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new Vector[n + 1] ;
            color = new int[n + 1] ;
            for(int i = 1 ; i <= n ; i++){
                adj[i] = new Vector<>() ;
            }
            while(m-- > 0){
                int u = scn.nextInt() , v = scn.nextInt() ;
                adj[u].add(v) ;
                adj[v].add(u) ;
            }
            Arrays.fill(color , -1) ;
            ArrayList<Integer> one = new ArrayList<>() , two = new ArrayList<>() ;
            for(int i = 1 ; i <= n ;i++){
                if(color[i] == -1){
                    dfs(i , 0) ;
                }
            }
            for(int i = 1 ; i <= n ; i++){
                if(color[i] == 0) {
                    one.add(i) ;
                } else {
                    two.add(i) ;
                }
            }
            if(one.size() < two.size()){
                System.out.println(one.size()) ;
                for(int x : one){
                    System.out.print(x + " ");
                }
            } else {
                out.write(two.size() + "\n") ;
                for(int x : two){
                    out.write(x + " ");
                }
            }
            out.write("\n") ;
        }
        out.flush() ;

    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

public class CF_1110 {

    static ArrayList<Integer>[] adj ;
    static boolean[] vis , vis1 ;
    static ArrayList<Integer> al  ;
    static void dfs(int u){
        al.add(u) ;
        for(int v : adj[u]){
            vis[v] = true ;
        }
    }

    static void dfs(int u  , PriorityQueue<int[]> pq){
        vis[u] = true ;
        pq.add(new int[]{adj[u].size() , u}) ;
        for(int v : adj[u]){
            if(!vis[v]){
                dfs(v , pq) ;
            }
        }
    }
    public static void main(String[] args) {
        FastReader scn = new FastReader() ;
        int t = scn.nextInt();
        while(t-- > 0){
            int n = scn.nextInt() , m = scn.nextInt() ;
            adj = new ArrayList[n + 1]  ;
            for(int i = 1 ; i<= n ; i++){
                adj[i] = new ArrayList<>() ;
            }
            al = new ArrayList<>() ;
            vis = new boolean[n + 1] ;
            while(m-- > 0){
                int x = scn.nextInt() , y = scn.nextInt() ;
                adj[x].add(y) ;
                adj[y].add(x) ;
            }
            PriorityQueue<int[]> pq = new PriorityQueue<>((a,b) -> (a[0] - b[0])) ;
            dfs(1, pq) ;
            Arrays.fill(vis , false) ;
            while(!pq.isEmpty()){
                int[] p = pq.poll() ;
                if(!vis[p[1]]){
                    dfs(p[1]) ;
                }
            }
            System.out.println(al.size());
            for(int x : al){
                System.out.print(x + " ");
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static int[] color;
	static boolean[] visited;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			color = new int[n];
			color[0] = 1;
			visited = new boolean[n];
			visited[0] = true;
			deefus(0,0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC < evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void deefus(int node, int lvl) {
		for(int i = 0; i < adj.get(node).size(); i++) {
			if(!visited[adj.get(node).get(i)]){
				color[adj.get(node).get(i)] = lvl%2;
				visited[adj.get(node).get(i)] = true;
				deefus(adj.get(node).get(i), lvl+1);
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static int[] color;
	static boolean[] visited;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			color = new int[n];
			color[0] = 0;
			visited = new boolean[n];
			visited[0] = true;
			deefus(0,0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC < evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void deefus(int node, int lvl) {
		for(int i = 0; i < adj.get(node).size(); i++) {
			if(!visited[adj.get(node).get(i)]){
				color[adj.get(node).get(i)] = lvl%2;
				visited[adj.get(node).get(i)] = true;
				deefus(adj.get(node).get(i), lvl+1);
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static int[] color;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			color = new int[n];
			color[0] = 1;
			beefus(0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC < evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void beefus(int node) {
		LinkedList<Integer> toVisit = new LinkedList<Integer>();
		ArrayList<Integer> allVisit = new ArrayList<Integer>();
		for (int i : adj.get(node)) {
			toVisit.add(i);
			allVisit.add(i);
		}
		allVisit.add(0);
		int loc = 0, len = toVisit.size(), c = 0;
		while (toVisit.size() != 0) {
			int val = toVisit.pop();
			c++;
			color[val] = loc % 2;
			for (int i : adj.get(val)) {
				if (!allVisit.contains(i)) {
					toVisit.add(i);
					allVisit.add(i);
				}
			}
			if (c == len) {
				len = toVisit.size();
				c = 0;
				loc++;
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static ArrayList<Integer> od;
	static ArrayList<Integer> ev;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			od = new ArrayList<Integer>();
			ev = new ArrayList<Integer>();
			od.add(0);
			beefus(0);
			if(od.size() < ev.size()){
				System.out.println(od.size());
				for(int i: od){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}else{
				System.out.println(ev.size());
				for(int i: ev){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}
		}
		sc.close();
	}

	public static void beefus(int node){
		LinkedList<Integer> toVisit = adj.get(node);
		int loc = 0, len = toVisit.size(), c = 0;
		while(!(toVisit.size()==0)){
			int val = toVisit.pop();
			c++;
			if(!od.contains(val) && !ev.contains(val)){
				if(loc%2 == 0){
					ev.add(val);
					for(int i: adj.get(val)){
						toVisit.add(i);
					}
				}else{
					od.add(val);
					for(int i: adj.get(val)){
						toVisit.add(i);
					}
				}
			}
			if(c==len){
				len = toVisit.size();
				c = 0;
				loc++;
			}
		}
	}

}


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

public class Sol {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for (int qwe = 0; qwe < t; qwe++) {
			int n = sc.nextInt();
			ArrayList<Integer>[] adj = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList<Integer>();
			}
			int m = sc.nextInt();
			for (int i = 0; i < m; i++) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			int[] d = new int[n];
			Arrays.fill(d,-1);
			d[0] = 0;
			LinkedList<Integer> bfs = new LinkedList<Integer>();
			bfs.add(0);
			while (bfs.size() != 0) {
				int val = bfs.pop();
				for (int i : adj[val]) {
					if (d[i] == -1) {
						d[i] = (d[val] + 1)%2;
						bfs.add(i);
					}
				}
			}
			int odC = 0, evC = 0;
			for (int i : d) {
				if (i == 1) {
					odC++;
				} else {
					evC++;
				}
			}
			if (odC <= evC) {
				System.out.println(odC);
				for (int i = 0; i < n; i++)
					if (d[i] == 1)
						System.out.print(i + 1 + " ");
				System.out.println();
			} else {
				System.out.println(evC);
				for (int i = 0; i < n; i++)
					if (d[i] == 0)
						System.out.print(i + 1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}
}


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

public class Sol {
	static ArrayList<Integer>[] adj;
	static int[] color;
	static boolean[] visited;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList[n];
			for(int i = 0; i < n; i++){
				adj[i] = new ArrayList<Integer>();
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj[a].add(b);
				adj[b].add(a);
			}
			color = new int[n];
			visited = new boolean[n];
			deefus(0,0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC < evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void deefus(int node, int lvl) {
		color[node] = lvl%2;
		visited[node] = true;
		for(int i = 0; i < adj[node].size(); i++) {
			if(!visited[adj[node].get(i)]){
				deefus(adj[node].get(i), lvl+1);
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static ArrayList<Integer> od;
	static ArrayList<Integer> ev;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			od = new ArrayList<Integer>();
			ev = new ArrayList<Integer>();
			od.add(0);
			beefus(0);
			if(od.size() < ev.size()){
				System.out.println(od.size());
				for(int i: od){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}else{
				System.out.println(ev.size());
				for(int i: ev){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}
		}
		sc.close();
	}

	public static void beefus(int node){
		LinkedList<Integer> toVisit = new LinkedList<Integer>();
		ArrayList<Integer> allVisit = new ArrayList<Integer>();
		for(int i: adj.get(node)){
			toVisit.add(i);
			allVisit.add(i);
		}
		allVisit.add(0);
		int loc = 0, len = toVisit.size(), c = 0;
		while(toVisit.size()!=0){
			int val = toVisit.pop();
			c++;
			if(loc%2 == 0){
				ev.add(val);
			}else{
				od.add(val);
			}
			for(int i: adj.get(val)){
				if(!allVisit.contains(i)){
					toVisit.add(i);
					allVisit.add(i);
				}
			}
			if(c==len){
				len = toVisit.size();
				c = 0;
				loc++;
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static int[] color;
	static boolean[] visited;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			color = new int[n];
			visited = new boolean[n];
			deefus(0,0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC < evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void deefus(int node, int lvl) {
		color[node] = lvl%2;
		visited[node] = true;
		for(int i = 0; i < adj.get(node).size(); i++) {
			if(!visited[adj.get(node).get(i)]){
				deefus(adj.get(node).get(i), lvl+1);
			}
		}
	}

}


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

public class Sol {
	static ArrayList<LinkedList<Integer>> adj;
	static ArrayList<Integer> od;
	static ArrayList<Integer> ev;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			int m = sc.nextInt();
			adj = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < n; i++){
				adj.add(new LinkedList<Integer>());
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			od = new ArrayList<Integer>();
			ev = new ArrayList<Integer>();
			od.add(0);
			beefus(0);
			if(od.size() < ev.size()){
				System.out.println(od.size());
				for(int i: od){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}else{
				System.out.println(ev.size());
				for(int i: ev){
					System.out.print(i+1 + " ");
				}
				System.out.println();
			}
		}
		sc.close();
	}

	public static void beefus(int node){
		LinkedList<Integer> toVisit = adj.get(node);
		int loc = 0, len = toVisit.size(), c = 0;
		while(!(toVisit.size()==0)){
			int val = toVisit.pop();
			c++;
			if(loc%2 == 0){
				ev.add(val);
			}else{
				od.add(val);
			}
			for(int i: adj.get(val)){
				if(!od.contains(val) && !ev.contains(val)){
					toVisit.add(i);
				}
			}
			if(c==len){
				len = toVisit.size();
				c = 0;
				loc++;
			}
		}
	}

}


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

public class Sol {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		} else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		Solver solver = new Solver();
		solver.solve(br, pw);
	}

	static class Solver {
		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			int t = br.nextInt();
			for (int qwe = 0; qwe < t; qwe++) {
				int n = br.nextInt();
				ArrayList<Integer>[] adj = new ArrayList[n];
				for (int i = 0; i < n; i++) {
					adj[i] = new ArrayList<Integer>();
				}
				int m = br.nextInt();
				for (int i = 0; i < m; i++) {
					int a = br.nextInt() - 1;
					int b = br.nextInt() - 1;
					adj[a].add(b);
					adj[b].add(a);
				}
				int[] d = new int[n];
				Arrays.fill(d, -1);
				d[0] = 0;
				LinkedList<Integer> bfs = new LinkedList<Integer>();
				bfs.add(0);
				while (bfs.size() != 0) {
					int val = bfs.pop();
					for (int i : adj[val]) {
						if (d[i] == -1) {
							d[i] = (d[val] + 1) % 2;
							bfs.add(i);
						}
					}
				}
				int odC = 0, evC = 0;
				for (int i : d) {
					if (i == 1) {
						odC++;
					} else {
						evC++;
					}
				}
				if (odC <= evC) {
					pw.println(odC);
					for (int i = 0; i < n; i++)
						if (d[i] == 1)
							pw.print(i + 1 + " ");
					pw.println();
				} else {
					pw.println(evC);
					for (int i = 0; i < n; i++)
						if (d[i] == 0)
							pw.print(i + 1 + " ");
					pw.println();
				}
			}
		pw.close();
		}
	}

	 //fastscanner class
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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


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

public class Sol {
	static ArrayList<Integer>[] adj;
	static int[] color;
	static boolean[] visited;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int qwe = 0; qwe < t; qwe++){
			int n = sc.nextInt();
			adj = new ArrayList[n];
			color = new int[n];
			visited = new boolean[n];
			for(int i = 0; i < n; i++){
				adj[i] = new ArrayList<Integer>();
			}
			int m = sc.nextInt();
			for(int i = 0; i < m; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				adj[a].add(b);
				adj[b].add(a);
			}
			deefus(0,0);
			int odC = 0, evC = 0;
			for(int i : color){
				if(i==1){
					odC++;
				}else{
					evC++;
				}
			}
			if(odC <= evC){
				System.out.println(odC);
				for(int i = 0; i < n; i++)
					if(color[i]==1)
						System.out.print(i+1 + " ");
				System.out.println();
			}else{
				System.out.println(evC);
				for(int i = 0; i < n; i++)
					if(color[i]==0)
						System.out.print(i+1 + " ");
				System.out.println();
			}
		}
		sc.close();
	}

	public static void deefus(int node, int lvl) {
		color[node] = lvl;
		visited[node] = true;
		for(int i : adj[node]) {
			if(!visited[i]){
				deefus(i, (lvl+1)%2);
			}
		}
	}

}