import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {
	/**
	 * ??\?????????????????? / ????????????????????????
	 */
	public static void main(String[] args) throws Exception {

		// ??\???????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int verticalLineCount = Integer.parseInt(br.readLine());
		// ???????????????????£??????° ???????????????
		String[] verticalLine = new String[verticalLineCount];
		List<String> goalNumberList = Arrays.asList(verticalLine);

		List<List<String>> allSideLine = processAllSideLine(br);

		goalNumberList = processGoalNumberList(goalNumberList, allSideLine);

		// ???????????????
		for (String string : goalNumberList) {

			System.out.println(string);
		}
	}

	/**
	 * ??¨???????¨??£?????????¨??????????´??????????????¬?????????????????????????
	 */
	public static List<List<String>> processAllSideLine(BufferedReader br) throws IOException {

		int sideLineCount = Integer.parseInt(br.readLine());
		List<List<String>> allSideLine = new ArrayList<>();

		for (int i = 0; i < sideLineCount; i++) {

			String[] sideLine = br.readLine().split(",");
			List<String> sideLineToList = Arrays.asList(sideLine);
			allSideLine.add(sideLineToList);
		}

		return allSideLine;
	}

	/**
	 * ????????????????????????????????????????????????????????§?????????????????????????????????????????§????????????
	 */
	public static List<String> processGoalNumberList(List<String> goalNumberList, List<List<String>> allSideLine) {

		for (int startNumber = 0; startNumber < goalNumberList.size(); startNumber++) {

			String goalNumber = String.valueOf(startNumber + 1);

			for (int j = 0; j < allSideLine.size(); j++) {

				String sideNode_1 = allSideLine.get(j).get(0);
				String sideNode_2 = allSideLine.get(j).get(1);

				if (sideNode_1.equals(goalNumber)) {

					goalNumber = sideNode_2;
				} else if (sideNode_2.equals(goalNumber)) {

					goalNumber = sideNode_1;
				}
			}

			goalNumberList.set(Integer.parseInt(goalNumber) - 1, String.valueOf(startNumber + 1));
		}

		return goalNumberList;
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz