Internet Problem Solving Contest

IPSC 2006

Problem R – Medical Research

Professor Moriarty decided to do a new research. He and his team have chosen a school with many students and they intended to perform some biometric measurements on a random sample chosen from students of that school. The director assembled all the students in one line on the school football ground, sorted from the shortest to the tallest student. Professor Moriarty drew out of his bag a book titled "The Large All Purpose Random Number Table" and read a few first numbers R1, R2, ... ,Rk. He asked students standing on the R1-th, R2-th, ..., Rk-th places from the left to come. The first thing, that the Professor wanted to know, was the height of each of the students.

Problem specification

In those days, they had no computers. Nowadays, all student's data are stored in a computer. It is an easy task to extract students' heights from a school database. The only problem is that the heights are not sorted and the database may be very large. Your task is to write a program that reads all heights of the students, random numbers selected by the Professor and outputs heights of selected students.

Input specification

Input file consists of several test cases. First line of the file contains a single integer N - the number of test cases. The case descriptions follow. Each case description consists of two lines. First line contains several positive integers, representing heights of students in centimeters, consecutive numbers separated by single space. The line is ended by a single number 0. None of the students is more than 2 meters tall. Second line also consists of positive integers, separated by single spaces and ending with a 0. It contains Professor's random numbers R1, ..., Rk. None of them is larger than the total number of students.

Output specification

Output file contains a single line for each test case. This line contains several numbers separated by single space. For each random number Ri it contains height of the Ri-th shortest student.


180 152 191 160 99 160 175 0
3 7 1 5 0
119 108 114 101 113 116 0
2 6 0
160 191 99 175
108 119