public static void main(String[] args) {
		Kattio io = new Kattio(System.in, System.out);

		int n = io.getInt();
		int m = io.getInt();

		HashMap<String, List<String>> translations = new HashMap<>();
		for (int i = 1; i < n + 1; i++) {
			String ia = i + "A";
			String ib = i + "B";
			String ic = i + "C";
			String[] temp = { ib, ic };

			translations.put(ia, Arrays.asList(temp));
			translations.put(ib, Arrays.asList(ia));
			translations.put(ic, Arrays.asList(ia));
		}

		HashMap<String, String> originalData = new HashMap<>();
		for (int i = 0; i < m; i++) {
			String first = io.getWord();
			String second = io.getWord();
			originalData.put(first, second);
			originalData.put(second, first);
		}

		HashMap<String, List<String>> graph = new HashMap<>();

		for (Entry<String, String> edge : originalData.entrySet()) {

			List<String> list = translations.get(edge.getKey());
			for (String str : list)
				modifyGraph(graph, str, edge.getValue());
		}

		Queue<State> q = new ArrayDeque<>();
		String start = "1A";
		q.add(new State(null, start));
		HashSet<String> visited = new HashSet<>();
		visited.add(start);
		String result = "Impossible";
		while (!q.isEmpty()) {

			State currentState = q.poll();
			List<String> neighbours = graph.get(currentState.vertex);
			if (neighbours != null)
				for (String neighbour : neighbours) {
					if (neighbour.equals(start)) {
						result = toPath(new State(currentState, start), n, originalData);
						q.clear();
						break;
					}
					if (visited.contains(neighbour)) {
						continue;
					}

					visited.add(neighbour);
					q.add(new State(currentState, neighbour));
				}
		}

		io.println(result);
		io.close();
	}