Under construction

Still being built. Things may change

Knowns and Unknowns

Time limit3sMemory limit2048 MB

Summary
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 nn students, numbered with integers from 11 to nn. Each professor's order is a permutation of the 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 who were at the university today. All students in AA visited both professors, and all students outside AA 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 AA are missing. For students a professor knows, the list contains their identifier. For students the professor does not know, the list contains −1-1.

For example, suppose the first professor's order is [1,2,3,4][1, 2, 3, 4] and the second professor's order is [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]. From these lists, we can immediately see that three students visited the university today. The set AA is either {1,2,3}\{1, 2, 3\} or {1,3,4}\{1, 3, 4\}.

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 TT (T≥1T \ge 1), the number of test cases.

Each test case has the following format. The first line contains nn (1≤n≤20001 \le n \le 2000), the number of students. The second line contains nn distinct integers p1,1,p1,2,…,p1,np_{1,1}, p_{1,2}, \ldots, p_{1,n}, the order of the first professor, where student p1,1p_{1,1} comes first and p1,np_{1,n} comes last (1≤p1,i≤n1 \le p_{1,i} \le n). The third line contains nn distinct integers p2,1,p2,2,…,p2,np_{2,1}, p_{2,2}, \ldots, p_{2,n}, the order of the second professor in the same format. The fourth line contains kk (1≤k≤n1 \le k \le n), the number of students who visited the university today. The fifth line contains kk integers s1,1,s1,2,…,s1,ks_{1,1}, s_{1,2}, \ldots, s_{1,k}, the first professor's list. The sixth line contains kk integers s2,1,s2,2,…,s2,ks_{2,1}, s_{2,2}, \ldots, s_{2,k}, the second professor's list. Each entry is either −1-1 or an integer from 11 to nn, and each student appears in each list at most once.

The sum of nn 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 nn characters. The ii-th character is Y if student ii visited the university today, N if student ii did not, and ? if it cannot be determined.

Examples2

  1. Example 1

    Input
    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
    
    Expected output
    Y?Y?
    Inconsistent
    
  2. Example 2

    Input
    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
    
    Expected output
    YYN
    Inconsistent