luogu#P12102. [NERC2024] Knowns and Unknowns

[NERC2024] Knowns and Unknowns

题目描述

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 some fixed order of the students in which they should visit the professor. There are nn students denoted with integers from 11 to nn. Each professor's order of students is a permutation of numbers from 11 to nn.

Today only some of the students visited the university; let AA be the set of numbers that denote the students that were at the university today. All of the students from the set AA have visited both professors, and all of the students outside of the set AA haven't visited any professor.

Each of the professors made a list of the students they have talked with, in the same order the students have visited. Note that the list has to correspond to the order the professor has established, with the only difference that the students outside of the set AA are missing in it. It is the beginning of the year, so the professors didn't have a chance to get to know every student. So for the students that a professor knows, the list contains their identifier, but for those that the professor doesn't know, the list contains 1-1.

Consider an example: the first professor's order is [1,2,3,4][1, 2, 3, 4], and the second professor's --- [3,2,4,1][3, 2, 4, 1]. The list made by the first professor today is [1,1,1][1, -1, -1], and the list made by the second professor is [3,1,1][3, -1, 1]. Based on the lists, we can immediately see that three students have visited the university today. We can infer that the set AA was either {1,2,3}\{1, 2, 3\} or {1,3,4}\{1, 3, 4\}.

You are given two permutations --- the orders established by each professor; you are also given two lists that professors made today. Your task is to help the professors. Based on the provided data, determine for each student whether they definitely visited the university, definitely did not, or whether this cannot be determined. Note that professors could have confused the students, so there is a possibility that the given data is inconsistent.

输入格式

The first line contains a single integer TT (T1T \ge 1) --- the number of test cases to solve.

Then the description of test cases follows.

The first line of the test case contains a single integer nn --- the number of students (1n20001 \le n \le 2000).

The second line of the test case contains nn distinct integers p1,1,p1,2,,p1,np_{1, 1}, p_{1, 2}, \ldots, p_{1, n} --- the order established by the first professor, meaning that student p1,1p_{1, 1} comes first, and p1,np_{1, n} comes last (1p1,in1 \le p_{1, i} \le n).

The third line of the test case contains nn distinct integers p2,1,p2,2,,p2,np_{2, 1}, p_{2, 2}, \ldots, p_{2, n} --- the order established by the second professor in the same format (1p2,in1 \le p_{2, i} \le n).

The fourth line of the test case contains an integer kk --- the number of students that visited the university today (1kn1 \le k \le n).

The fifth line of the test case contains kk integers s1,1,s1,2,,s1,ks_{1, 1}, s_{1, 2}, \ldots, s_{1, k} --- the first professor's list. Each student appears in the list at most once (s1,i=1s_{1, i} = -1 or 1s1,in1 \le s_{1, i} \le n).

The sixth line of the test case contains kk integers s2,1,s2,2,,s2,ks_{2, 1}, s_{2, 2}, \ldots, s_{2, k} --- the second professor's list in the same format (s2,i=1s_{2, i} = -1 or 1s2,in1 \le s_{2, i} \le n).

The total sum of nn in all TT test cases doesn't exceed 2000.

输出格式

For each test case, output a single string. If the given data is inconsistent, print a single word Inconsistent\tt{Inconsistent}. Otherwise, print a string consisting of nn characters, the ii-th of which is Y\tt{Y} if the ii-th student visited the university today, N\tt{N} if the ii-th student didn't visit the university today, or ?\tt{?} if it cannot be determined.

2
4
1 2 3 4
3 2 4 1
3
1 -1 -1
3 -1 1
4
1 2 3 4
3 2 4 1
3
1 -1 2
3 -1 1
Y?Y?
Inconsistent
2
3
1 2 3
2 1 3
2
-1 2
-1 -1
3
1 2 3
3 2 1
2
1 3
2 -1
YYN
Inconsistent