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;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util 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;
	}
} 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);
		}
	} main {

		// ??\???????????????
		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);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int verticalLineCount = Integer.parseInt(br.readLine()); verticalLineCount Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String[] verticalLine = new String[verticalLineCount]; verticalLine new String[verticalLineCount] verticalLineCount List<String> goalNumberList = Arrays.asList(verticalLine); goalNumberList Arrays.asList(verticalLine) Arrays.asList Arrays verticalLine List<List<String>> allSideLine = processAllSideLine(br); allSideLine processAllSideLine(br) processAllSideLine br goalNumberList = processGoalNumberList(goalNumberList, allSideLine) goalNumberList processGoalNumberList(goalNumberList, allSideLine) processGoalNumberList goalNumberList allSideLine for (String string : goalNumberList) {

			System.out.println(string);
		} String string goalNumberList {

			System.out.println(string);
		} {

			System.out.println(string);
		} System.out.println(string) System.out.println System.out System System.out string String[] args args /**
	 * ??¨???????¨??£?????????¨??????????´??????????????¬?????????????????????????
	 */
	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;
	} processAllSideLine {

		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;
	} int sideLineCount = Integer.parseInt(br.readLine()); sideLineCount Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br List<List<String>> allSideLine = new ArrayList<>(); allSideLine new ArrayList<>() for (int i = 0; i < sideLineCount; i++) {

			String[] sideLine = br.readLine().split(",");
			List<String> sideLineToList = Arrays.asList(sideLine);
			allSideLine.add(sideLineToList);
		} int i = 0; int i = 0; i 0 i < sideLineCount i sideLineCount i++ i++ i {

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

			String[] sideLine = br.readLine().split(",");
			List<String> sideLineToList = Arrays.asList(sideLine);
			allSideLine.add(sideLineToList);
		} String[] sideLine = br.readLine().split(","); sideLine br.readLine().split(",") br.readLine().split br.readLine() br.readLine br "," List<String> sideLineToList = Arrays.asList(sideLine); sideLineToList Arrays.asList(sideLine) Arrays.asList Arrays sideLine allSideLine.add(sideLineToList) allSideLine.add allSideLine sideLineToList return allSideLine; allSideLine BufferedReader br br /**
	 * ????????????????????????????????????????????????????????§?????????????????????????????????????????§????????????
	 */
	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;
	} processGoalNumberList {

		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;
	} 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));
		} int startNumber = 0; int startNumber = 0; startNumber 0 startNumber < goalNumberList.size() startNumber goalNumberList.size() goalNumberList.size goalNumberList startNumber++ startNumber++ 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));
		} {

			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));
		} String goalNumber = String.valueOf(startNumber + 1); goalNumber String.valueOf(startNumber + 1) String.valueOf String startNumber + 1 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;
				}
			} int j = 0; int j = 0; j 0 j < allSideLine.size() j allSideLine.size() allSideLine.size allSideLine j++ j++ 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;
				}
			} {

				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;
				}
			} String sideNode_1 = allSideLine.get(j).get(0); sideNode_1 allSideLine.get(j).get(0) allSideLine.get(j).get allSideLine.get(j) allSideLine.get allSideLine j 0 String sideNode_2 = allSideLine.get(j).get(1); sideNode_2 allSideLine.get(j).get(1) allSideLine.get(j).get allSideLine.get(j) allSideLine.get allSideLine j 1 if (sideNode_1.equals(goalNumber)) {

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

					goalNumber = sideNode_1;
				} sideNode_1.equals(goalNumber) sideNode_1.equals sideNode_1 goalNumber {

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

					goalNumber = sideNode_1;
				} sideNode_2.equals(goalNumber) sideNode_2.equals sideNode_2 goalNumber {

					goalNumber = sideNode_1;
				} goalNumber = sideNode_1 goalNumber sideNode_1 goalNumberList.set(Integer.parseInt(goalNumber) - 1, String.valueOf(startNumber + 1)) goalNumberList.set goalNumberList Integer.parseInt(goalNumber) - 1 Integer.parseInt(goalNumber) Integer.parseInt Integer goalNumber 1 String.valueOf(startNumber + 1) String.valueOf String startNumber + 1 startNumber 1 return goalNumberList; goalNumberList List<String> goalNumberList goalNumberList List<List<String>> allSideLine allSideLine
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;
	}
}