public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		int nCase = 0;
		while ((line = in.readLine()) != null && line.length() != 0) {
			if (nCase++ != 0)
				out.append("\n");
			String[] vars = line.trim().split(" ");
			size = vars.length;
			map = new int[200];
			map2 = new char[size + 1];
			ady = new ArrayList[size + 1];
			parents = new int[size + 1];
			int id = 1;
			for (int i = 0; i < size; i++) {
				char l = vars[i].charAt(0);
				map[l] = id;
				map2[id++] = l;
			}
			for (int i = 0; i <= size; i++)
				ady[i] = new ArrayList<Integer>(30);
			String[] ins = in.readLine().trim().split(" ");
			for (int i = 0; i < ins.length; i += 2) {
				int a = map[ins[i].charAt(0)];
				int b = map[ins[i + 1].charAt(0)];
				ady[a].add(b);
				parents[b]++;
			}
			for (int i = 1; i < parents.length; i++)
				if (parents[i] == 0) {
					parents[i]++;
					ady[0].add(i);
				}
			ans = new ArrayList<String>();
			DFS(0, 0, 0, "");
			Collections.sort(ans);
			for (String path : ans)
				out.append(path + "\n");
		}
		System.out.print(out);
	}