Ladies’ Choice

Teenagers from the local high school have asked you to help them with the organization of next year’s Prom. The idea is to find a suitable date for everyone in the class in a fair and civilized way. So, they have organized a web site where all students, boys and girls, state their preferences among the class members, by ordering all the possible candidates. Your mission is to keep everyone as happy as possible. Assume that there are equal numbers of boys and girls. Given a set of preferences, set up the blind dates such that there are no other two people of opposite sex who would both rather have each other than their current partners. Since it was decided that the Prom was Ladies’ Choice, we want to produce the best possible choice for the girls. Input Input consists of multiple test cases the first line of the input contains the number of test cases. There is a blank line before each dataset. The input for each dataset consists of a positive integer N, not greater than 1,000, indicating the number of couples in theclass. Next, there are N lines, each onecontaining the all the integers from 1 to N,ordered according to the girl’s preferences. Next, there are N lines, each one containing all the integers from 1 to N, ordered according to the boy’s preferences. Output The output for each dataset consists of a sequence of N lines, where the i-th line containsthe number of the boy assigned to the i-th girl (from 1 to N). Print a blank line between datasets. Sample Input 1 5 12354 52431 35124 34215 45123 25413 32415 12435 41253 53241 Sample Output 1 2 5 3 4