public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int T = readInt();
        while (T-- > 0) {
            N = readInt();
            int M = readInt();
            map = new boolean[N][N];
            for (int i = 0; i < M; i++) {
                int a = readInt() - 1;
                int b = readInt() - 1;
                map[a][b] = true;
                map[b][a] = true;
            }
            int start = 0, minDegree = N;
            for (int i = 0; i < N; i++) {
                int degree = 0;
                for (int j = 0; j < N; j++) {
                    if (map[i][j]) {
                        degree++;
                    }
                }
                if (degree < minDegree) {
                    minDegree = degree;
                    start = i;
                }
            }
            colored = new boolean[N];
            result = new ArrayList<Integer>();
            max = 0;
            colored[start] = true;
            System.arraycopy(map[start], 0, colored, 0, N);
            List<Integer> temp = new ArrayList<Integer>();
            recurse(temp);
            pw.println(result.size());
            for (int i = 0; i < result.size() - 1; i++) {
                pw.print((result.get(i) + 1) + " ");
            }
            try {
                pw.println(result.get(result.size() - 1) + 1);
            } catch (Exception e) {
                pw.println(0);
            }
            pw.flush();
        }
        pw.close();
    }