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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Osmanys Alonso (osmanys@gmail.com)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int u, v, m = in.readInt();
            Graph g = new Graph(n);
            for (int i = 0; i < m; i++) {
                u = in.readInt() - 1;
                v = in.readInt() - 1;
                g.addSimpleEdge(u, v);
                g.addSimpleEdge(v, u);
            }
            boolean selected[] = new boolean[n];
            boolean visited[] = new boolean[n];
            int r = n;
            int idx = 0;
            while (idx < n && r >= n / 2) {
                r = go(g, idx, visited, selected);
                idx++;
            }
            out.printLine(r);
            for (int i = 0; i < n; i++) {
                if (selected[i])
                    out.print((i + 1) + " ");
            }
            out.printLine();
        }

        private int go(Graph g, int v, boolean visited[], boolean selected[]) {
            visited[v] = true;
            int next;
            Edge edge;
            boolean found = false;
            for (int e = g.firstOutbound(v); e != -1; e = g.nextOutbound(e)) {
                edge = g.edge(e);
                next = edge.getDestination();
                if (selected[next]) {
                    found = true;
                    break;
                }
            }
            int r = 0;
            if (!found) {
                selected[v] = true;
                r++;
            }
            for (int e = g.firstOutbound(v); e != -1; e = g.nextOutbound(e)) {
                edge = g.edge(e);
                next = edge.getDestination();
                if (!visited[next])
                    r += go(g, next, visited, selected);
            }
            return r;
        }

    }

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

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

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

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static interface Edge {
        public int getDestination();

    }

    static class Graph {
        public static final int REMOVED_BIT = 0;
        protected int vertexCount;
        protected int edgeCount;
        private int[] firstOutbound;
        private int[] firstInbound;
        private Edge[] edges;
        private int[] nextInbound;
        private int[] nextOutbound;
        private int[] from;
        private int[] to;
        private long[] weight;
        public long[] capacity;
        private int[] reverseEdge;
        private int[] flags;

        public Graph(int vertexCount) {
            this(vertexCount, vertexCount);
        }

        public Graph(int vertexCount, int edgeCapacity) {
            this.vertexCount = vertexCount;
            firstOutbound = new int[vertexCount];
            Arrays.fill(firstOutbound, -1);

            from = new int[edgeCapacity];
            to = new int[edgeCapacity];
            nextOutbound = new int[edgeCapacity];
            flags = new int[edgeCapacity];
        }

        public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {
            ensureEdgeCapacity(edgeCount + 1);
            if (firstOutbound[fromID] != -1) {
                nextOutbound[edgeCount] = firstOutbound[fromID];
            } else {
                nextOutbound[edgeCount] = -1;
            }
            firstOutbound[fromID] = edgeCount;
            if (firstInbound != null) {
                if (firstInbound[toID] != -1) {
                    nextInbound[edgeCount] = firstInbound[toID];
                } else {
                    nextInbound[edgeCount] = -1;
                }
                firstInbound[toID] = edgeCount;
            }
            this.from[edgeCount] = fromID;
            this.to[edgeCount] = toID;
            if (capacity != 0) {
                if (this.capacity == null) {
                    this.capacity = new long[from.length];
                }
                this.capacity[edgeCount] = capacity;
            }
            if (weight != 0) {
                if (this.weight == null) {
                    this.weight = new long[from.length];
                }
                this.weight[edgeCount] = weight;
            }
            if (reverseEdge != -1) {
                if (this.reverseEdge == null) {
                    this.reverseEdge = new int[from.length];
                    Arrays.fill(this.reverseEdge, 0, edgeCount, -1);
                }
                this.reverseEdge[edgeCount] = reverseEdge;
            }
            if (edges != null) {
                edges[edgeCount] = createEdge(edgeCount);
            }
            return edgeCount++;
        }

        protected final GraphEdge createEdge(int id) {
            return new GraphEdge(id);
        }

        public final int addFlowWeightedEdge(int from, int to, long weight, long capacity) {
            if (capacity == 0) {
                return addEdge(from, to, weight, 0, -1);
            } else {
                int lastEdgeCount = edgeCount;
                addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());
                return addEdge(from, to, weight, capacity, lastEdgeCount);
            }
        }

        protected int entriesPerEdge() {
            return 1;
        }

        public final int addWeightedEdge(int from, int to, long weight) {
            return addFlowWeightedEdge(from, to, weight, 0);
        }

        public final int addSimpleEdge(int from, int to) {
            return addWeightedEdge(from, to, 0);
        }

        public final Edge edge(int id) {
            initEdges();
            return edges[id];
        }

        public final int firstOutbound(int vertex) {
            int id = firstOutbound[vertex];
            while (id != -1 && isRemoved(id)) {
                id = nextOutbound[id];
            }
            return id;
        }

        public final int nextOutbound(int id) {
            id = nextOutbound[id];
            while (id != -1 && isRemoved(id)) {
                id = nextOutbound[id];
            }
            return id;
        }

        public final int destination(int id) {
            return to[id];
        }

        protected final void initEdges() {
            if (edges == null) {
                edges = new Edge[from.length];
                for (int i = 0; i < edgeCount; i++) {
                    edges[i] = createEdge(i);
                }
            }
        }

        public final boolean flag(int id, int bit) {
            return (flags[id] >> bit & 1) != 0;
        }

        public final boolean isRemoved(int id) {
            return flag(id, REMOVED_BIT);
        }

        protected void ensureEdgeCapacity(int size) {
            if (from.length < size) {
                int newSize = Math.max(size, 2 * from.length);
                if (edges != null) {
                    edges = resize(edges, newSize);
                }
                from = resize(from, newSize);
                to = resize(to, newSize);
                nextOutbound = resize(nextOutbound, newSize);
                if (nextInbound != null) {
                    nextInbound = resize(nextInbound, newSize);
                }
                if (weight != null) {
                    weight = resize(weight, newSize);
                }
                if (capacity != null) {
                    capacity = resize(capacity, newSize);
                }
                if (reverseEdge != null) {
                    reverseEdge = resize(reverseEdge, newSize);
                }
                flags = resize(flags, newSize);
            }
        }

        protected final int[] resize(int[] array, int size) {
            int[] newArray = new int[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        private long[] resize(long[] array, int size) {
            long[] newArray = new long[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        private Edge[] resize(Edge[] array, int size) {
            Edge[] newArray = new Edge[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        protected class GraphEdge implements Edge {
            protected int id;

            protected GraphEdge(int id) {
                this.id = id;
            }

            public int getDestination() {
                return destination(id);
            }

        }

    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Osmanys Alonso (osmanys@gmail.com)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int u, v, m = in.readInt();
            Graph g = new Graph(n);
            int cnt[] = new int[n];
            for (int i = 0; i < m; i++) {
                u = in.readInt() - 1;
                v = in.readInt() - 1;
                g.addSimpleEdge(u, v);
                g.addSimpleEdge(v, u);
                cnt[u]++;
                cnt[v]++;
            }
            boolean selected[] = new boolean[n];
            boolean visited[];
            int r = n;
            int max = 0, idx = 0;
            for (int i = 0; i < n; i++) {
                if (max < cnt[i]) {
                    max = cnt[i];
                    idx = i;
                }
            }
            while (idx < n && r > n / 2) {
                selected = new boolean[n];
                visited = new boolean[n];
                r = go(g, idx, visited, selected);
                idx++;
            }
            out.printLine(r);
            for (int i = 0; i < n; i++) {
                if (selected[i])
                    out.print((i + 1) + " ");
            }
            out.printLine();
        }

        private int go(Graph g, int v, boolean visited[], boolean selected[]) {
            visited[v] = true;
            int next;
            Edge edge;
            boolean found = false;
            for (int e = g.firstOutbound(v); e != -1; e = g.nextOutbound(e)) {
                edge = g.edge(e);
                next = edge.getDestination();
                if (selected[next]) {
                    found = true;
                    break;
                }
            }
            int r = 0;
            if (!found) {
                selected[v] = true;
                r++;
            }
            for (int e = g.firstOutbound(v); e != -1; e = g.nextOutbound(e)) {
                edge = g.edge(e);
                next = edge.getDestination();
                if (!visited[next])
                    r += go(g, next, visited, selected);
            }
            return r;
        }

    }

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

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

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

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static interface Edge {
        public int getDestination();

    }

    static class Graph {
        public static final int REMOVED_BIT = 0;
        protected int vertexCount;
        protected int edgeCount;
        private int[] firstOutbound;
        private int[] firstInbound;
        private Edge[] edges;
        private int[] nextInbound;
        private int[] nextOutbound;
        private int[] from;
        private int[] to;
        private long[] weight;
        public long[] capacity;
        private int[] reverseEdge;
        private int[] flags;

        public Graph(int vertexCount) {
            this(vertexCount, vertexCount);
        }

        public Graph(int vertexCount, int edgeCapacity) {
            this.vertexCount = vertexCount;
            firstOutbound = new int[vertexCount];
            Arrays.fill(firstOutbound, -1);

            from = new int[edgeCapacity];
            to = new int[edgeCapacity];
            nextOutbound = new int[edgeCapacity];
            flags = new int[edgeCapacity];
        }

        public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {
            ensureEdgeCapacity(edgeCount + 1);
            if (firstOutbound[fromID] != -1) {
                nextOutbound[edgeCount] = firstOutbound[fromID];
            } else {
                nextOutbound[edgeCount] = -1;
            }
            firstOutbound[fromID] = edgeCount;
            if (firstInbound != null) {
                if (firstInbound[toID] != -1) {
                    nextInbound[edgeCount] = firstInbound[toID];
                } else {
                    nextInbound[edgeCount] = -1;
                }
                firstInbound[toID] = edgeCount;
            }
            this.from[edgeCount] = fromID;
            this.to[edgeCount] = toID;
            if (capacity != 0) {
                if (this.capacity == null) {
                    this.capacity = new long[from.length];
                }
                this.capacity[edgeCount] = capacity;
            }
            if (weight != 0) {
                if (this.weight == null) {
                    this.weight = new long[from.length];
                }
                this.weight[edgeCount] = weight;
            }
            if (reverseEdge != -1) {
                if (this.reverseEdge == null) {
                    this.reverseEdge = new int[from.length];
                    Arrays.fill(this.reverseEdge, 0, edgeCount, -1);
                }
                this.reverseEdge[edgeCount] = reverseEdge;
            }
            if (edges != null) {
                edges[edgeCount] = createEdge(edgeCount);
            }
            return edgeCount++;
        }

        protected final GraphEdge createEdge(int id) {
            return new GraphEdge(id);
        }

        public final int addFlowWeightedEdge(int from, int to, long weight, long capacity) {
            if (capacity == 0) {
                return addEdge(from, to, weight, 0, -1);
            } else {
                int lastEdgeCount = edgeCount;
                addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());
                return addEdge(from, to, weight, capacity, lastEdgeCount);
            }
        }

        protected int entriesPerEdge() {
            return 1;
        }

        public final int addWeightedEdge(int from, int to, long weight) {
            return addFlowWeightedEdge(from, to, weight, 0);
        }

        public final int addSimpleEdge(int from, int to) {
            return addWeightedEdge(from, to, 0);
        }

        public final Edge edge(int id) {
            initEdges();
            return edges[id];
        }

        public final int firstOutbound(int vertex) {
            int id = firstOutbound[vertex];
            while (id != -1 && isRemoved(id)) {
                id = nextOutbound[id];
            }
            return id;
        }

        public final int nextOutbound(int id) {
            id = nextOutbound[id];
            while (id != -1 && isRemoved(id)) {
                id = nextOutbound[id];
            }
            return id;
        }

        public final int destination(int id) {
            return to[id];
        }

        protected final void initEdges() {
            if (edges == null) {
                edges = new Edge[from.length];
                for (int i = 0; i < edgeCount; i++) {
                    edges[i] = createEdge(i);
                }
            }
        }

        public final boolean flag(int id, int bit) {
            return (flags[id] >> bit & 1) != 0;
        }

        public final boolean isRemoved(int id) {
            return flag(id, REMOVED_BIT);
        }

        protected void ensureEdgeCapacity(int size) {
            if (from.length < size) {
                int newSize = Math.max(size, 2 * from.length);
                if (edges != null) {
                    edges = resize(edges, newSize);
                }
                from = resize(from, newSize);
                to = resize(to, newSize);
                nextOutbound = resize(nextOutbound, newSize);
                if (nextInbound != null) {
                    nextInbound = resize(nextInbound, newSize);
                }
                if (weight != null) {
                    weight = resize(weight, newSize);
                }
                if (capacity != null) {
                    capacity = resize(capacity, newSize);
                }
                if (reverseEdge != null) {
                    reverseEdge = resize(reverseEdge, newSize);
                }
                flags = resize(flags, newSize);
            }
        }

        protected final int[] resize(int[] array, int size) {
            int[] newArray = new int[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        private long[] resize(long[] array, int size) {
            long[] newArray = new long[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        private Edge[] resize(Edge[] array, int size) {
            Edge[] newArray = new Edge[size];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        protected class GraphEdge implements Edge {
            protected int id;

            protected GraphEdge(int id) {
                this.id = id;
            }

            public int getDestination() {
                return destination(id);
            }

        }

    }
}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int round=0;round<t;round++){
            HashSet visited = new HashSet();
            int max = 2*(int)Math.pow(10,5)+1;
//            System.out.println("Max:"+max);
            ArrayList<ArrayList<Integer>>mark = new ArrayList<>(max);
            for (int i=0;i<max;i++){
                mark.add(new ArrayList<>());
            }
            String [] input = br.readLine().split(" ");
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            for(int i=1;i<=vertices;i++){
                mark.get(node.get(i).size()).add(i);
            }
            for(int i=max-1;i>0;i--){
                if (mark.get(i).size()>0)
                    for(int j=0;j<mark.get(i).size();j++){
                        int now = mark.get(i).get(j);
//                        System.out.println("Before"+visited);
                        if(!visited.contains(now)){
                            visited.add(now);
                            ans.add(now);
                            for(int x :node.get(now))
                                visited.add(x);
//                            System.out.println("Now"+now+"Visited"+visited);
                        }

                    }

                if(visited.size()==vertices){
//                    System.out.println("break");
                    break;
                }

            }
            System.out.println(ans.size());
            for(int i=0;i<ans.size();i++)
                System.out.print(ans.get(i)+" ");
//            printArrayList(node,vertices);
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        int max = 2*(int)Math.pow(10,5)+1;
        for(int round=0;round<t;round++){
            boolean [] queue = new boolean[max];
            queue[1]=true;
            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            int turn=1;
            run.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                    if(turn==1){
                        odd.add(next);
                    }
                    else even.add(next);
                    for(int x:node.get(next)){
                        if (!queue[x]){
                            temp.add(x);
                            queue[x]=true;
                        }

                    }

                if (run.size()==0) {
                    run = (ArrayList<Integer>) temp.clone();
                    temp.clear();
                    turn ^= 1;
                }
            }
//            System.out.println(queue);
            if (even.size()<odd.size()){
                System.out.println(even.size());
                for(int v:even)
                    System.out.print(v+" ");
            }
            else {
                System.out.println(odd.size());
                for(int v:odd)
                    System.out.print(v+" ");
            }
            System.out.println();
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int round=0;round<t;round++){
            HashSet queue = new HashSet();
            int c=1;
            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            int turn=1;
            run.add(1);
            queue.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                if(turn==1)odd.add(next);
                else even.add(next);
                for(int x:node.get(next)){
                    if (!queue.contains(x)){
                        c++;
                        temp.add(x);
                        queue.add(x);
                    }

                }
                if (run.size()==0) {
                    run = (ArrayList<Integer>) temp.clone();
                    temp.clear();
                    turn ^= 1;
                }
            }
//            System.out.println(queue);
            if (even.size()<odd.size()){
                System.out.println(even.size());
                for(int v:even)
                    System.out.print(v+" ");
            }
            else {
                System.out.println(odd.size());
                for(int v:odd)
                    System.out.print(v+" ");
            }
            System.out.println();
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import jdk.internal.org.objectweb.asm.tree.InnerClassNode;

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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        HashSet visited = new HashSet();
        for(int round=0;round<t;round++){
            String [] input = br.readLine().split(" ");
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            for(int i=1;i<=vertices;i++){
                if (!visited.contains(i)){
                    ans.add(i);
                    for(int j=0;j<node.get(i).size();j++){
                        visited.add(node.get(i).get(j));
                    }
                }

            }
            System.out.println(ans.size());
            for(int i=0;i<ans.size();i++)
                System.out.print(ans.get(i)+" ");
//            printArrayList(node,vertices);
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int round=0;round<t;round++){
            HashSet visited = new HashSet();
            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            int turn=1;
            run.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                if (!visited.contains(next)){
                    visited.add(next);
                    if(turn==1){
                        odd.add(next);
                    }
                    else even.add(next);
                    for(int x:node.get(next)){
                        if (!visited.contains(x))
                            temp.add(x);
                    }
                }
                if (run.size()==0) {
                    run = (ArrayList<Integer>) temp.clone();
                    temp.clear();
                    turn ^= 1;
                }
            }
            if (even.size()<odd.size()){
                System.out.println(even.size());
                for(int v:even)
                    System.out.print(v+" ");
            }
            else {
                System.out.println(odd.size());
                for(int v:odd)
                    System.out.print(v+" ");
            }
            System.out.println();
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        HashSet visited = new HashSet();
        for(int round=0;round<t;round++){
            String [] input = br.readLine().split(" ");
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            for(int i=1;i<=vertices;i++){
                if (!visited.contains(i)){
                    ans.add(i);
                    for(int j=0;j<node.get(i).size();j++){
                        visited.add(node.get(i).get(j));
                    }
                }

            }
            System.out.println(ans.size());
            for(int i=0;i<ans.size();i++)
                System.out.print(ans.get(i)+" ");
//            printArrayList(node,vertices);
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        HashSet visited = new HashSet();
        for(int round=0;round<t;round++){
            int max = 2*(int)Math.pow(10,5)+1;
//            System.out.println("Max:"+max);
            ArrayList<ArrayList<Integer>>mark = new ArrayList<>(max);
            for (int i=0;i<max;i++){
                mark.add(new ArrayList<>());
            }
            String [] input = br.readLine().split(" ");
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            for(int i=1;i<=vertices;i++){
                mark.get(node.get(i).size()).add(i);
            }
            for(int i=max-1;i>0;i--){
                if (mark.get(i).size()>0)
                    for(int j=0;j<mark.get(i).size();j++){
                        int now = mark.get(i).get(j);
                        if(!visited.contains(now)){
                            visited.add(now);
                            ans.add(now);
                            for(int x :node.get(now))
                                visited.add(x);
                        }
                    }
                if(visited.size()==vertices){
                    break;
                }

            }
            System.out.println(ans.size());
            for(int i=0;i<ans.size();i++)
                System.out.print(ans.get(i)+" ");
//            printArrayList(node,vertices);
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        HashSet visited = new HashSet();
        for(int round=0;round<t;round++){
            int max = 2*(int)Math.pow(10,5)+1;
//            System.out.println("Max:"+max);
            ArrayList<ArrayList<Integer>>mark = new ArrayList<>(max);
            for (int i=0;i<max;i++){
                mark.add(new ArrayList<>());
            }
            String [] input = br.readLine().split(" ");
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            for(int i=1;i<=vertices;i++){
                mark.get(node.get(i).size()).add(i);
            }
            for(int i=max-1;i>0;i--){
                if (mark.get(i).size()>0)
                    for(int j=0;j<mark.get(i).size();j++){
                        int now = mark.get(i).get(j);
                        if(!visited.contains(now)){
                            ans.add(now);
                            for(int x :node.get(now))
                                visited.add(x);
                        }
                    }

            }
            System.out.println(ans.size());
            for(int i=0;i<ans.size();i++)
                System.out.print(ans.get(i)+" ");
//            printArrayList(node,vertices);
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = in.nextInt();
//        System.out.println("T:"+t);
        for(int round=0;round<t;round++){
            HashSet queue = new HashSet();
            int c=1;
//            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = in.nextInt();
            int edges = in.nextInt();
//            System.out.println("vertice:"+vertices+"edge:"+edges);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            int a=0;int b=0;
            for(int i=0;i<edges;i++){
//                input = br.readLine().split(" ");
                a = in.nextInt();
                b = in.nextInt();
//                System.out.println("A:"+a+"B:"+b);
                node.get(a).add(b);
                node.get(b).add(a);
            }
//            System.out.println("Finish!!");
//            int turn=1;
            run.add(1);
            queue.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                odd.add(next);
                for(int x:node.get(next)){
                    if (!queue.contains(x)){
                        temp.add(x);
                        queue.add(x);
                    }

                }
                if (run.size()==0) {
                    while (temp.size()>0){
                        next = temp.get(0);
                        temp.remove(0);
                        even.add(next);
                        for(int x:node.get(next)){
                            if (!queue.contains(x)){
                                run.add(x);
                                queue.add(x);
                            }

                        }

                    }

                }
            }
//            System.out.println(queue);
//            printArrayList(node,vertices);
            if (even.size()<odd.size()){
                out.println(even.size());
                for(int v:even)
                    out.print(v+" ");
            }
            else {
                out.println(odd.size());
                for(int v:odd)
                    out.print(v+" ");
            }
            out.println();
        }
        out.close();
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Scanner;
public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = in.nextInt();
        for(int round=0;round<t;round++){
            int c=1;
            LinkedList<Integer> run = new LinkedList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = in.nextInt();
            int edges = in.nextInt();
            boolean[] queue = new boolean[vertices + 1];
            ArrayList<Integer>[] node = new ArrayList[vertices+1];
            for (int i = 0; i <= vertices; i++) {
                node[i] = new ArrayList<>();
            }
            int a=0;int b=0;
            for(int i=0;i<edges;i++){
                a = in.nextInt();
                b = in.nextInt();
                node[a].add(b);
                node[b].add(a);
            }
            run.add(1);
//            queue.add(1);
            queue[1 ] = true;
            LinkedList<Integer> temp = new LinkedList<>();
            while (run.size()>0){
                int next = run.removeFirst();
                odd.add(next);
                for(int x:node[next]){
                    if (!queue[x]){
                        temp.addLast(x);
                        queue[x] = true;
                    }

                }
                if (run.size()==0) {
                    while (temp.size()>0){
                        next = temp.removeFirst();
                        even.add(next);
                        for(int x:node[next]){
                            if (!queue[x]){
                                run.addLast(x);
                                queue[x]=true;
                            }

                        }

                    }

                }
            }
            if (even.size()<odd.size()){
                out.println(even.size());
                for(int v:even)
                    out.print(v+" ");
            }
            else {
                out.println(odd.size());
                for(int v:odd)
                    out.print(v+" ");
            }
            out.println();
        }
        out.close();
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int round=0;round<t;round++){
            HashSet queue = new HashSet();
            HashSet visited = new HashSet();
            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            ArrayList<Integer> ans = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
            int turn=1;
            run.add(1);
            queue.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                if (!visited.contains(next)){
                    visited.add(next);
                    if(turn==1){
                        odd.add(next);
                    }
                    else even.add(next);
                    for(int x:node.get(next)){
                        if (!queue.contains(x)){
                            temp.add(x);
                            queue.add(x);
                        }

                    }
                }
                if (run.size()==0) {
                    run = (ArrayList<Integer>) temp.clone();
                    temp.clear();
                    turn ^= 1;
                }
            }
//            System.out.println(queue);
            if (even.size()<odd.size()){
                System.out.println(even.size());
                for(int v:even)
                    System.out.print(v+" ");
            }
            else {
                System.out.println(odd.size());
                for(int v:odd)
                    System.out.print(v+" ");
            }
            System.out.println();
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = in.nextInt();
        for(int round=0;round<t;round++){
            int c=1;
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = in.nextInt();
            int edges = in.nextInt();
            boolean[] queue = new boolean[vertices + 1];
            ArrayList<Integer>[] node = new ArrayList[vertices+1];
            for (int i = 0; i <= vertices; i++) {
                node[i] = new ArrayList<>();
            }
            int a=0;int b=0;
            for(int i=0;i<edges;i++){
                a = in.nextInt();
                b = in.nextInt();
                node[a].add(b);
                node[b].add(a);
            }
            run.add(1);
//            queue.add(1);
            queue[1 ] = true;
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                odd.add(next);
                for(int x:node[next]){
                    if (!queue[x]){
                        temp.add(x);
                        queue[x] = true;
                    }

                }
                if (run.size()==0) {
                    while (temp.size()>0){
                        next = temp.get(0);
                        temp.remove(0);
                        even.add(next);
                        for(int x:node[next]){
                            if (!queue[x]){
                                run.add(x);
                                queue[x]=true;
                            }

                        }

                    }

                }
            }
            if (even.size()<odd.size()){
                out.println(even.size());
                for(int v:even)
                    out.print(v+" ");
            }
            else {
                out.println(odd.size());
                for(int v:odd)
                    out.print(v+" ");
            }
            out.println();
        }
        out.close();
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


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

public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int round=0;round<t;round++){
            HashSet queue = new HashSet();
            int c=1;
            String [] input = br.readLine().split(" ");
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = Integer.parseInt(input[0]);
            int edges = Integer.parseInt(input[1]);
            ArrayList<ArrayList<Integer>> node = new ArrayList<>(vertices+1);
            for(int i=0;i<=vertices;i++){
                node.add(new ArrayList<>());
            }
            for(int i=0;i<edges;i++){
                input = br.readLine().split(" ");
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[1]);
                node.get(a).add(b);
                node.get(b).add(a);
            }
//            int turn=1;
            run.add(1);
            queue.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                odd.add(next);
                for(int x:node.get(next)){
                    if (!queue.contains(x)){
                        temp.add(x);
                        queue.add(x);
                    }

                }
                if (run.size()==0) {
                    while (temp.size()>0){
                        next = temp.get(0);
                        temp.remove(0);
                        even.add(next);
                        for(int x:node.get(next)){
                            if (!queue.contains(x)){
                                run.add(x);
                                queue.add(x);
                            }

                        }

                    }

                }
            }
//            System.out.println(queue);
            if (even.size()<odd.size()){
                System.out.println(even.size());
                for(int v:even)
                    System.out.print(v+" ");
            }
            else {
                System.out.println(odd.size());
                for(int v:odd)
                    System.out.print(v+" ");
            }
            System.out.println();
        }
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class ECoverit {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = in.nextInt();
        for(int round=0;round<t;round++){
            HashSet queue = new HashSet();
            int c=1;
            ArrayList<Integer> run = new ArrayList<>();
            ArrayList<Integer> even = new ArrayList<>();
            ArrayList<Integer> odd = new ArrayList<>();
            int vertices = in.nextInt();
            int edges = in.nextInt();
            ArrayList<Integer>[] node = new ArrayList[vertices+1];
            for (int i = 0; i <= vertices; i++) {
                node[i] = new ArrayList<>();
            }
            int a=0;int b=0;
            for(int i=0;i<edges;i++){
                a = in.nextInt();
                b = in.nextInt();
                node[a].add(b);
                node[b].add(a);
            }
            run.add(1);
            queue.add(1);
            ArrayList<Integer> temp = new ArrayList<>();
            while (run.size()>0){
                int next = run.get(0);
                run.remove(0);
                odd.add(next);
                for(int x:node[next]){
                    if (!queue.contains(x)){
                        temp.add(x);
                        queue.add(x);
                    }

                }
                if (run.size()==0) {
                    while (temp.size()>0){
                        next = temp.get(0);
                        temp.remove(0);
                        even.add(next);
                        for(int x:node[next]){
                            if (!queue.contains(x)){
                                run.add(x);
                                queue.add(x);
                            }

                        }

                    }

                }
            }
            if (even.size()<odd.size()){
                out.println(even.size());
                for(int v:even)
                    out.print(v+" ");
            }
            else {
                out.println(odd.size());
                for(int v:odd)
                    out.print(v+" ");
            }
            out.println();
        }
        out.close();
    }
    static void printArrayList(ArrayList<ArrayList<Integer>> arr,int amount){
        for(int i=1;i<=amount;i++)
            System.out.println(arr.get(i));

    }

}


import java.util.*;
import java.util.function.IntConsumer;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;

import static java.lang.Math.min;

public class Main {
    static void dfs(Map<Integer, Integer> ds, Map<Integer, List<Integer>> adj, int node, int d, Set<Integer> parents) {
        ds.put(node, d);
        parents.add(node);
        if (adj.containsKey(node)) {
            for (Integer integer : adj.get(node)) {
                if (!parents.contains(integer)) {
                    dfs(ds, adj, integer, d + 1, parents);
                }
            }
        }
        parents.remove(node);
    }

    static IntStream solution(Map<Integer, List<Integer>> adj) {
        Map<Integer, Integer> ds = new HashMap<>();
        dfs(ds, adj, 1, 0, new HashSet<>());
        int even = 0;
        int odd = 0;
        for (Map.Entry<Integer, Integer> integerIntegerEntry : ds.entrySet()) {
            if (integerIntegerEntry.getValue() % 2 == 0) {
                even += 1;
            } else {
                odd += 1;
            }
        }

        if (even <= odd) {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 == 0)
                    .mapToInt(Map.Entry::getKey);
        } else {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 != 0)
                    .mapToInt(Map.Entry::getKey);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            scanner.nextInt();
            int m = scanner.nextInt();
            Map<Integer, List<Integer>> adj = new HashMap<>();
            for (int j = 0; j < m; j++) {
                int u = scanner.nextInt();
                int v = scanner.nextInt();
                if (!adj.containsKey(u)) {
                    adj.put(u, new ArrayList<>());
                }
                if (!adj.containsKey(v)) {
                    adj.put(v, new ArrayList<>());
                }
                adj.get(u).add(v);
                adj.get(v).add(u);
            }
            StringBuilder s = new StringBuilder();
            final int[] c = {0};
            IntStream solution = solution(adj);
            solution.forEach(value -> {
                c[0] += 1;
                s.append(value + " ");
            });
            s.deleteCharAt(s.length() - 1);
            System.out.println(c[0]);
            System.out.println(s.toString());
        }

    }
}


import java.util.*;
import java.util.function.IntConsumer;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;

import static java.lang.Math.min;

public class Main {
    static void dfs(Map<Integer, Integer> ds, Map<Integer, List<Integer>> adj, int node, int d, Set<Integer> parents) {
        ds.put(node, d);
        parents.add(node);
        if (adj.containsKey(node)) {
            for (Integer integer : adj.get(node)) {
                if (!parents.contains(integer)) {
                    dfs(ds, adj, integer, d + 1, parents);
                }
            }
        }
//        parents.remove(node);
    }

    static IntStream solution(Map<Integer, List<Integer>> adj) {
        Map<Integer, Integer> ds = new HashMap<>();
        dfs(ds, adj, 1, 0, new HashSet<>());
        int even = 0;
        int odd = 0;
        for (Map.Entry<Integer, Integer> integerIntegerEntry : ds.entrySet()) {
            if (integerIntegerEntry.getValue() % 2 == 0) {
                even += 1;
            } else {
                odd += 1;
            }
        }

        if (even <= odd) {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 == 0)
                    .mapToInt(Map.Entry::getKey);
        } else {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 != 0)
                    .mapToInt(Map.Entry::getKey);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            scanner.nextInt();
            int m = scanner.nextInt();
            Map<Integer, List<Integer>> adj = new HashMap<>();
            for (int j = 0; j < m; j++) {
                int u = scanner.nextInt();
                int v = scanner.nextInt();
                if (!adj.containsKey(u)) {
                    adj.put(u, new ArrayList<>());
                }
                if (!adj.containsKey(v)) {
                    adj.put(v, new ArrayList<>());
                }
                adj.get(u).add(v);
                adj.get(v).add(u);
            }
            StringBuilder s = new StringBuilder();
            final int[] c = {0};
            IntStream solution = solution(adj);
            solution.forEach(value -> {
                c[0] += 1;
                s.append(value + " ");
            });
            s.deleteCharAt(s.length() - 1);
            System.out.println(c[0]);
            System.out.println(s.toString());
        }

    }
}


import java.util.*;
import java.util.function.IntConsumer;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;

import static java.lang.Math.min;

public class Main {
    static void dfs(Map<Integer, Integer> ds, Map<Integer, List<Integer>> adj, int node, int d, Set<Integer> parents) {
        ds.put(node, d);
        parents.add(node);
        if (adj.containsKey(node)) {
            for (Integer integer : adj.get(node)) {
                if (!parents.contains(integer)) {
                    dfs(ds, adj, integer, d + 1, parents);
                }
            }
        }
//        parents.remove(node);
    }

    static int[] solution(Map<Integer, List<Integer>> adj) {
        Map<Integer, Integer> ds = new HashMap<>();
        dfs(ds, adj, 1, 0, new HashSet<>());
        int even = 0;
        int odd = 0;
        for (Map.Entry<Integer, Integer> integerIntegerEntry : ds.entrySet()) {
            if (integerIntegerEntry.getValue() % 2 == 0) {
                even += 1;
            } else {
                odd += 1;
            }
        }

        if (even <= odd) {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 == 0)
                    .mapToInt(Map.Entry::getKey).toArray();
        } else {
            return ds.entrySet().stream().filter(integerIntegerEntry -> integerIntegerEntry.getValue() % 2 != 0)
                    .mapToInt(Map.Entry::getKey).toArray();
        }
    }

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

        for (int i = 0; i < n; i++) {
            scanner.nextInt();
            int m = scanner.nextInt();
            Map<Integer, List<Integer>> adj = new HashMap<>();
            for (int j = 0; j < m; j++) {
                int u = scanner.nextInt();
                int v = scanner.nextInt();
                if (!adj.containsKey(u)) {
                    adj.put(u, new ArrayList<>());
                }
                if (!adj.containsKey(v)) {
                    adj.put(v, new ArrayList<>());
                }
                adj.get(u).add(v);
                adj.get(v).add(u);
            }
            int[] solution = solution(adj);
            s.append(solution.length);
            s.append("\n");
            for (int i1 : solution) {
                s.append(i1);
                s.append(" ");
            }
            s.append("\n");
        }
        System.out.println(s.toString());

    }
}


import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            Set<Integer> vertexes = new HashSet<>(n/2);
            Set<Integer> used = new HashSet<>(n);
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(vertexes.contains(v1)){
                    used.add(v2);
                }else if(vertexes.contains(v2)){
                    used.add(v1);
                }else if(!used.contains(v1) && !used.contains(v2)){
                    vertexes.add(v1);
                    used.add(v2);
                }

            }

            sb.append(vertexes.size()).append('\n');
            for (int val: vertexes) {
                sb.append(val).append(' ');
            }
            sb.append('\n');
        }
        writer.write(sb.substring(0, sb.length()-1));
        writer.flush();

    }

}


import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            Set<Integer> vertexes = new HashSet<>(n/2);
            Set<Integer> used = new HashSet<>(n/2);
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(vertexes.contains(v1)){
                    if(!vertexes.contains(v2))
                        used.add(v2);
                }else if(vertexes.contains(v2)){
                    if(!vertexes.contains(v1))
                        used.add(v1);
                }else if(!used.contains(v1)){
                    vertexes.add(v1);
                    used.add(v2);
                }else if(!used.contains(v2)){
                    vertexes.add(v2);
                }
            }

            if(vertexes.size() < used.size()){
                writer.write(vertexes.size() + "\n");
                for (int val: vertexes) {
                    writer.write(val + " ");
                }
            }else{
                writer.write(used.size() + "\n");
                for (int val: used) {
                    writer.write(val + " ");
                }
            }

            writer.write("\n");
        }
        writer.flush();

    }

}


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

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

//            Set<Integer> vertexes = new HashSet<>(n/2);
//            Set<Integer> used = new HashSet<>(n);
            Map<Integer, List<Integer>> graph = new HashMap<>();
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(!graph.containsKey(v1))
                    graph.put(v1, new ArrayList<>());
                if(!graph.containsKey(v2))
                    graph.put(v2, new ArrayList<>());

                graph.get(v1).add(v2);
                graph.get(v2).add(v1);
//                if(vertexes.contains(v1)){
//                    used.add(v2);
//                }else if(vertexes.contains(v2)){
//                    used.add(v1);
//                }else if(!used.contains(v1)){
//                    vertexes.add(v1);
//                    used.add(v2);
//                }else if(!used.contains(v2)){
//                    vertexes.add(v2);
//                }

            }

            Set<Integer> vertexes = getVertexes(graph, n);
            writer.write(vertexes.size() + "\n");
            for (int val: vertexes) {
                writer.write(val + " ");
            }
            writer.write("\n");
        }
        writer.flush();

    }

    private Set<Integer> getVertexes(Map<Integer, List<Integer>> graph, int vSize){

        Queue<Integer> queue = new LinkedList<>();
        boolean[] visited = new boolean[vSize+1];
        Set<Integer> vertexes = new HashSet<>(vSize/2);
        Set<Integer> used = new HashSet<>(vSize);
        queue.add(1);

        while (!queue.isEmpty()){

            int v = queue.poll();
            visited[v] = true;

            boolean useless = false;
            if(!used.contains(v)) {
                vertexes.add(v);
                useless = true;
            }
            for (int child: graph.get(v)) {

                if(visited[child])
                    continue;

                if(useless)
                    used.add(child);

                queue.add(child);
            }

        }

        return vertexes;
    }

}


import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            Set<Integer> vertexes = new HashSet<>(n/2);
            Set<Integer> used = new HashSet<>(n);
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(vertexes.contains(v1)){
                    used.add(v2);
                }else if(vertexes.contains(v2)){
                    used.add(v1);
                }else if(!used.contains(v1)){
                    vertexes.add(v1);
                    used.add(v2);
                }else if(!used.contains(v2)){
                    vertexes.add(v1);
                    used.add(v1);
                }

            }

            sb.append(vertexes.size()).append('\n');
            for (int val: vertexes) {
                sb.append(val).append(' ');
            }
            sb.append('\n');
        }
        writer.write(sb.substring(0, sb.length()-1));
        writer.flush();

    }

}


import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            Set<Integer> vertexes = new HashSet<>(n/2);
            Set<Integer> used = new HashSet<>(n);
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(vertexes.contains(v1)){
                    used.add(v2);
                }else if(vertexes.contains(v2)){
                    used.add(v1);
                }else if(!used.contains(v1) && !used.contains(v2)){
                    vertexes.add(v1);
                    used.add(v2);
                }

            }

            writer.write(vertexes.size() + "\n");
            for (int val: vertexes) {
                writer.write(val + " ");
            }
            writer.write("\n");
        }
        writer.flush();

    }

}


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

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            List<Node> graph = new ArrayList<>(n+1);
            for (int j = 0; j <= n; j++) {
                graph.add(new Node(j));
            }

            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                graph.get(v1).childs.add(graph.get(v2));
                graph.get(v2).childs.add(graph.get(v1));
            }

            boolean[] visited = new boolean[n+1];
            visited[0] = true;

            Set<Node> vertexes = new HashSet<>(n/2);
            PriorityQueue<Node> queue = new PriorityQueue<>(graph);
            while (!queue.isEmpty()){

                Node node = queue.poll();
                if(visited[node.v])
                    continue;

                vertexes.add(node);
                for (Node child: node.childs) {
                    visited[child.v] = true;
                }
            }

            writer.write(vertexes.size() + "\n");
            for (Node val: vertexes) {
                writer.write(val.v + " ");
            }
            writer.write("\n");
        }
        writer.flush();

    }

    private final class Node implements Comparable<Node>{
        int v;
        LinkedList<Node> childs;
        public Node(int v) {
            this.v = v;
            this.childs = new LinkedList<>();
        }
        @Override
        public int compareTo(Node o) {
            return Integer.compare(o.childs.size(), this.childs.size());
        }
    }

}


import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

    private void run() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int queries = Integer.parseInt(reader.readLine());

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        for (int i = 0; i < queries; i++) {

            String[] line = reader.readLine().split("\\s");
            int n = Integer.parseInt(line[0]), m = Integer.parseInt(line[1]);

            Set<Integer> vertexes = new HashSet<>(n/2);
            Set<Integer> used = new HashSet<>(n);
            for (int j = 0; j < m; j++) {

                line = reader.readLine().split("\\s");
                int v1 = Integer.parseInt(line[0]), v2 = Integer.parseInt(line[1]);

                if(vertexes.contains(v1)){
                    used.add(v2);
                }else if(vertexes.contains(v2)){
                    used.add(v1);
                }else if(!used.contains(v1)){
                    vertexes.add(v1);
                    used.add(v2);
                }else if(!used.contains(v2)){
                    vertexes.add(v2);
                }

            }

            writer.write(vertexes.size() + "\n");
            for (int val: vertexes) {
                writer.write(val + " ");
            }
            writer.write("\n");
        }
        writer.flush();

    }

}


import java.util.*;
import java.io.*;
public class Main{
     public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.valueOf(br.readLine());
        while(t!=0)
        {
            t--;
            String[]cmd=br.readLine().split(" ");
            int n=Integer.valueOf(cmd[0]);
            int m=Integer.valueOf(cmd[1]);
            int[]deg=new int[n+1];
            ArrayList<Integer>[]gr=new ArrayList[n+1];
            for(int i=0;i<=n;i++)
            {
                gr[i]=new ArrayList<>();
            }
            for(int i=0;i<m;i++)
            {
                cmd=br.readLine().split(" ");
                int x=Integer.valueOf(cmd[0]);
                int y=Integer.valueOf(cmd[1]);
                gr[x].add(y);
                gr[y].add(x);
                deg[x]++;
                deg[y]++;
            }
            PriorityQueue<Pair> pq=new PriorityQueue<>();
            for(int i=1;i<=n;i++)
            {
                pq.add(new Pair(i,deg[i]));
            }
            int req=n/2;
            System.out.println(req);
            int[]mark=new int[n+1];
            while(req!=0)
            {
                Pair p=pq.poll();
                if(p.deg!=deg[p.node] || mark[p.node]==1)
                continue;
                req--;
                mark[p.node]=1;
                System.out.print(p.node+" ");
                for(int i=0;i<gr[p.node].size();i++)
                {
                    int y=gr[p.node].get(i);
                    if(mark[y]==1)
                    continue;
                    deg[y]--;
                    pq.add(new Pair(y,deg[y]));
                }
            }
            System.out.println();
        }
     }
}
class Pair implements Comparable<Pair>
{
    int node;
    int deg;
    public Pair(int node,int deg)
    {
        this.node=node;
        this.deg=deg;
    }
    public int compareTo(Pair p)
    {
        return p.deg-this.deg;
    }
}


import java.util.*;
import java.io.*;
public class Codechef{
     public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.valueOf(br.readLine());
        while(t!=0)
        {
            t--;
            String[]cmd=br.readLine().split(" ");
            int n=Integer.valueOf(cmd[0]);
            int m=Integer.valueOf(cmd[1]);
            ArrayList<Integer>[]gr=new ArrayList[n+1];
            for(int i=0;i<=n;i++)
            {
                gr[i]=new ArrayList<>();
            }
            for(int i=0;i<m;i++)
            {
                cmd=br.readLine().split(" ");
                int x=Integer.valueOf(cmd[0]);
                int y=Integer.valueOf(cmd[1]);
                gr[x].add(y);
                gr[y].add(x);
            }
            int[]dis=new int[n+1];
            Queue<Integer>q=new LinkedList<>();
            q.add(1);
            dis[1]=0;
            int[]vis=new int[n+1];
            while(!q.isEmpty())
            {
                int node=q.poll();
                for(int i=0;i<gr[node].size();i++)
                {
                    int y=gr[node].get(i);
                    if(vis[y]==1)
                    continue;
                    vis[y]=1;
                    dis[y]=(dis[node]+1)%2;
                    q.add(y);
                }
            }
            ArrayList<Integer>odd=new ArrayList<>();
            ArrayList<Integer>even=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                if(dis[i]==0)
                even.add(i);
                else
                odd.add(i);
            }
            if(odd.size()<even.size())
            {
                System.out.println(odd.size());
                for(int i=0;i<odd.size();i++)
                {
                    System.out.print(odd.get(i)+" ");
                }
                System.out.println();
            }
            else
            {
                System.out.println(even.size());
                for(int i=0;i<even.size();i++)
                {
                    System.out.print(even.get(i)+" ");
                }
                System.out.println();
            }
        }
     }
}


import java.util.*;
import java.io.*;
public class Codechef{
     public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.valueOf(br.readLine());
        PrintWriter pr=new PrintWriter(new OutputStreamWriter(System.out));
        while(t!=0)
        {
            t--;
            String[]cmd=br.readLine().split(" ");
            int n=Integer.valueOf(cmd[0]);
            int m=Integer.valueOf(cmd[1]);
            ArrayList<Integer>[]gr=new ArrayList[n+1];
            for(int i=0;i<=n;i++)
            {
                gr[i]=new ArrayList<>();
            }
            for(int i=0;i<m;i++)
            {
                cmd=br.readLine().split(" ");
                int x=Integer.valueOf(cmd[0]);
                int y=Integer.valueOf(cmd[1]);
                gr[x].add(y);
                gr[y].add(x);
            }
            int[]dis=new int[n+1];
            Queue<Integer>q=new LinkedList<>();
            q.add(1);
            dis[1]=0;
            int[]vis=new int[n+1];
            while(!q.isEmpty())
            {
                int node=q.poll();
                for(int i=0;i<gr[node].size();i++)
                {
                    int y=gr[node].get(i);
                    if(vis[y]==1)
                    continue;
                    vis[y]=1;
                    dis[y]=(dis[node]+1)%2;
                    q.add(y);
                }
            }
            ArrayList<Integer>odd=new ArrayList<>();
            ArrayList<Integer>even=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                if(dis[i]==0)
                even.add(i);
                else
                odd.add(i);
            }
            if(odd.size()<even.size())
            {
                pr.write(odd.size()+"\n");
                for(int i=0;i<odd.size();i++)
                {
                    pr.write(odd.get(i)+" ");
                }
                pr.write("\n");
            }
            else
            {
                pr.write(even.size()+"\n");
                for(int i=0;i<even.size();i++)
                {
                    pr.write(even.get(i)+" ");
                }
                pr.write("\n");
            }
        }
        pr.flush();
     }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.reflect.Array;

public class E {
    static final int MOD = 1000000007; // 1e9 + 7
    static final boolean AUTO_FLUSH = false; // slow if true
    // int = num(); // long = ll();
    // string = next(); // a string line = line();
    // ---------------------------------- \
    HashSet<Integer> odd = new HashSet<>(), even = new HashSet<>();
    List<Integer>[] graph;
    BitSet vis = new BitSet();
    void main() throws Exception {
        int t = num();
        while (t-- > 0) {
            int n = num(), m = num();
            graph = new List[n+1];
            for (int i = 1; i <= n; i++)
                graph[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int a = num(), b = num();
                graph[a].add(b);
                graph[b].add(a);
            }
            odd.add(1);
            vis.set(1);
            dfs(1, 1);
            Set<Integer> set = odd.size() > even.size() ? even : odd;
            outln(set.size());
            for (int i : set)
                out(i + " ");
            outln();
            vis.clear();
            even.clear();
            odd.clear();
        }
    }
    void dfs(int i, int level) {
        List<Integer> list = new ArrayList<>();
        level++;
        for (int next : graph[i]) {
            if (!vis.get(next)) {
                vis.set(next);
                list.add(next);
                if (level%2 == 0)
                    even.add(next);
                else
                    odd.add(next);
            }
        }
        for (int next : list)
            dfs(next, level);
    }

    // ---------------------------------- \
    //#region
    public static void main(String[] args) throws Exception {
        new Thread(null, () -> {
            try {
                startTime();
                new E().main();
                boolean endsWithEnter = TO_BE_PRINTED.length() == 0 || TO_BE_PRINTED.charAt(TO_BE_PRINTED.length() - 1) == '\n';
                flush();
                if (!endsWithEnter)
                    log('\n');
                logTime();
                logMem();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Main", 1<<26).start();
    }
    static Random RAND = new Random();
    static int random(int from, int to) {
        return RAND.nextInt(to-from+1)+from;
    }
    static void logTime() {
        log("Time: " + getTime() + "ms");
    }
    static void logMem() {
        log("Memory (End): " + (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");
    }
    static long ll() {
        return Long.parseLong(next());
    }
    static int num() {
        return Integer.parseInt(next());
    }
    static void generateInputMode() throws Exception {
        System.setOut(new PrintStream(new FileOutputStream("F://PROGRAMMING/input.txt")));
    }
    static String line() {
        if (!tokenize())
            return null;
        INPUT_STREAM.setLength(0);
        if (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(STRING_TOKENIZER.nextToken());
        while (STRING_TOKENIZER.hasMoreTokens())
            INPUT_STREAM.append(' ').append(STRING_TOKENIZER.nextToken());
        return INPUT_STREAM.length() == 0 ? null : INPUT_STREAM.toString();
    }
    static void startTime() {
        TIME_COMPLEXITY = System.currentTimeMillis();
    }
    static long getTime() {
        return System.currentTimeMillis() - TIME_COMPLEXITY;
    }
    static void flush() {
        System.out.print(TO_BE_PRINTED.toString());
        TO_BE_PRINTED.setLength(0);
    }
    static void out(Object o) {
        TO_BE_PRINTED.append(o.toString());
        if (AUTO_FLUSH)
            flush();
    }
    static void _log(String s) {
        System.err.print(s);
    }
    static void _logln(String s) {
        System.err.println(s);
    }
    static void _logln() {
        System.err.println();
    }
    static void outln(Object o) {
        out(o);
        outln();
    }
    static void outln() {
        out("\n");
    }
    static class Pair implements Comparable<Pair> {
        public int a, b;
        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public static Pair of(int a, int b) {
            return new Pair(a, b);
        }
        public int compareTo(Pair p) {
            if (a == p.a)
                return Integer.compare(b, p.b);
            return Integer.compare(a, p.a);
        }
        public String toString() {
            return "[" + a + "," + b + "]";
        }
        public boolean equals(Pair p) {
            return p.a == a && p.b == b;
        }
    }
    static void logArr(Object val) {
        Class<?> valKlass = val.getClass();
        Object[] outputArray = null;
        for(Class<?> arrKlass : new Class<?>[] { int[].class, float[].class, double[].class, boolean[].class,
            byte[].class, short[].class, long[].class, char[].class }) {
            if (valKlass.isAssignableFrom(arrKlass)) {
                int arrlength = Array.getLength(val);
                outputArray = new Object[arrlength];
                for(int i = 0; i < arrlength; ++i)
                    outputArray[i] = Array.get(val, i);
                break;
            }
        }
        if(outputArray == null)
            outputArray = (Object[])val;
        logArr0(outputArray);
    }
    static void logArr0(Object[] objs) {
        _log("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            _log(objs[i].toString().equals("\n") ? "\n>" : (" " + objs[i]));
        _logln();
    }
    static void log(Object... objs) {
        logArr0(objs);
    }
    static String next() {
        return tokenize() ? STRING_TOKENIZER.nextToken() : null;
    }
    static boolean tokenize() {
        if (STRING_TOKENIZER == null || !STRING_TOKENIZER.hasMoreTokens()) {
            try {
                STRING_TOKENIZER = new StringTokenizer(STREAM_READER.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
    static long TIME_COMPLEXITY;
    static BufferedReader STREAM_READER = new BufferedReader(new InputStreamReader(System.in), 32768);
    static StringTokenizer STRING_TOKENIZER;
    static StringBuilder INPUT_STREAM = new StringBuilder(), TO_BE_PRINTED = new StringBuilder();
    //#endregion
}