public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int test = Integer.parseInt(line.trim()), v[];
			int nNodes, nEdges;
			for (int i = 0; i < test; i++) {
				v = retInts(in.readLine());
				nNodes = v[0];
				nEdges = v[1];
				list = new ArrayList[nNodes + 1];
				for (int j = 0; j < list.length; j++)
					list[j] = new ArrayList<Integer>();
				color = new boolean[nNodes + 1];
				ans = new boolean[nNodes + 1];
				nBlacks = 0;
				for (int j = 0; j < nEdges; j++) {
					v = retInts(in.readLine());
					list[v[0]].add(v[1]);
					list[v[1]].add(v[0]);
				}
				back(0, 0);
				out.append(nBlacks + "\n");
				for (int j = 1; j < ans.length; j++)
					if (ans[j])
						out.append(j + " ");
				if (nBlacks > 0)
					out.setLength(out.length() - 1);
				out.append("\n");
			}
		}
		System.out.print(out);
	}