Knowns and Unknowns
Time limit3sMemory limit2048 MB
Given two professor orders and their partial visit lists, decide for each student whether they attended, skipped, or cannot be determined.
- Level
Medium7 of 10
- Topics
- Array, String matching, Dynamic programming
- Solved
- No attempts yet
Problem
Two math professors have office hours on the same day. Students visit each professor to present their assignment solutions, one by one. For the whole semester, both professors established a fixed order of the students in which they should visit. There are students, numbered with integers from to . Each professor's order is a permutation of the numbers from to .
Today only some of the students visited the university. Let be the set of numbers that denote the students who were at the university today. All students in visited both professors, and all students outside did not visit any professor.
Each professor made a list of the students they talked with, in the order they visited. The list follows the professor's established order, except that students outside are missing. For students a professor knows, the list contains their identifier. For students the professor does not know, the list contains .
For example, suppose the first professor's order is and the second professor's order is . The list made by the first professor today is , and the list made by the second professor is . From these lists, we can immediately see that three students visited the university today. The set is either or .
Given the two permutations and the two lists, determine for each student whether they definitely visited the university, definitely did not, or whether this cannot be determined. The professors may have confused the students, so the data may be inconsistent.
Input
The first line contains a single integer (), the number of test cases.
Each test case has the following format. The first line contains (), the number of students. The second line contains distinct integers , the order of the first professor, where student comes first and comes last (). The third line contains distinct integers , the order of the second professor in the same format. The fourth line contains (), the number of students who visited the university today. The fifth line contains integers , the first professor's list. The sixth line contains integers , the second professor's list. Each entry is either or an integer from to , and each student appears in each list at most once.
The sum of over all test cases does not exceed 2000.
Output
For each test case, print one line. If the data is inconsistent, print Inconsistent. Otherwise, print a string of characters. The -th character is Y if student visited the university today, N if student did not, and ? if it cannot be determined.