#P11482. Laura's Necklace
Laura's Necklace
Laura's Necklace
Laura wants to create a new necklace by combining the colors from two existing necklaces A and B (each represented by a string). However, she wishes to avoid k "ugly" color pairs. In her unique method, for each pearl A_i in necklace A and for each pearl B_j in necklace B, she forms a color combination. If the combination \( A_iB_j \) is not one of the ugly pairs, she appends a new pearl with that combined color to the end of the new necklace.
You are given q queries. For the i-th query, an integer \( t_i \) is provided, asking for the color of the \( t_i\text{-th} \) pearl in the new necklace (1-indexed). It is guaranteed that \( t_i \) is valid.
Note: All formulas are in LaTeX format.
inputFormat
The input consists of the following lines:
- Line 1: A non-empty string representing necklace A.
- Line 2: A non-empty string representing necklace B.
- Line 3: An integer k, the number of ugly color pairs.
- The next k lines: Each line contains an ugly pair. Each ugly pair is represented by two characters (without spaces) where the first character comes from necklace A and the second from necklace B.
- Next line: An integer q, the number of queries.
- The following q lines: Each line contains an integer \( t_i \), representing a query for the \( t_i\text{-th} \) pearl in the new necklace.
outputFormat
For each query, output the color (a concatenation of the character from A and the character from B) of the corresponding pearl in the new necklace on a new line.
sample
abc
def
1
ad
3
1
4
8
ae
be
cf
</p>