import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

//@author Kyle Zeller

public class Main {
	public static void main (String[] args) throws FileNotFoundException, IOException {
        File f = new File(args[0]);
        BufferedReader read = new BufferedReader(new FileReader(f));

        String line;
        while ((line = read.readLine()) != null) {
			String randomExpr = line.split(";")[0];
			String[] words = randomExpr.split("\\s");
			
			String numSeq = line.split(";")[1];
			String[] intBuffer = numSeq.split("\\s");
			int[] indicies = new int[intBuffer.length];
			for (int i = 0; i < intBuffer.length; i++) {
				indicies[i] = Integer.parseInt(intBuffer[i]) - 1;
			}
			
			Hashtable<Integer, String> pairs = new Hashtable<Integer, String>();
			for (int i = 0; i < indicies.length; i++) {
				pairs.put(new Integer(indicies[i]), words[i]);
			}
			
			int counter = indicies.length;
			StringBuilder output = new StringBuilder();
			for (int i = 0; i < words.length; i++) {
				if(!pairs.containsKey(i)) {
					output.append(words[counter]);
					output.append(" ");
					counter++;
				}
				else {
					output.append(pairs.get(i));
					output.append(" ");
				}
			}
			
			System.out.println(output.toString().trim());
        }
	}
}