String Puzzle

Given equality hints between substrings of a huge implicit string plus some fixed letters, decide the letters at the queried positions. The hint structure is a partition of the string into sections, and a hint joins one section to an earlier same-length section, so the constraints are interval equalities on an unknown string of length n; the task is to propagate equality and fixed letters across positions, answering ? where a position's letter is not forced. The input size is small (at most 1000 hints and 1000 queries) but n can be 10^9, so positions cannot be enumerated directly and the hint/

Hard8StringUnion-findImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

The magazine Amazing Coding runs a puzzle contest in every issue and gives away the latest digital gadgets as prizes. Its readers are programmers, so the magazine asks them to solve the puzzles by writing programs.

The puzzle in the latest issue is about deciding some of the letters of a string, called the secret string below, from a collection of hints. The figure shows one example of the hints.

The first hint is the length of the secret string. In the figure it is nine, and the nine boxes correspond to nine letters. Letter positions, that is box numbers, are counted from 1, from the left to the right.

Hints of the second kind give the letter of the secret string at a specific position. In the figure, the letters in boxes 3, 4, 7, and 9 are C, I, C, and P.

Hints of the third kind are about repeated substrings of the secret string. The bar immediately below the boxes is cut into sections, each covering a substring of the secret string. A section may be joined by a line running to the left with another section of the same length. The substrings covered by two joined sections are equal. One hint in the figure says that the letters in boxes 8 and 9 equal the letters in boxes 4 and 5, and from that you get the substring IP.

Not every pair of equal substrings of the secret string appears among the hints. Some pairs are left out.

Two joined sections may also overlap. In the figure, the two letter substring in boxes 2 and 3 is said to equal the one in boxes 1 and 2, and the two sections share box 2.

In this example every position of the secret string can be decided, and the string is CCCIPCCIP. In general the hints may not be enough to decide every letter.

The answer to the puzzle is the letters at the asked positions. Write a question mark ? when the letter at an asked position cannot be decided from the given hints.

Input

The input consists of a single test case in the following format.

n a b q
x1 c1
.
.
.
xa ca
y1 h1
.
.
.
yb hb
z1
.
.
.
zq

The first line contains four integers nn, aa, bb, and qq. Here nn (1n109)(1 \le n \le 10^9) is the length of the secret string, aa (0a1000)(0 \le a \le 1000) is the number of hints on letters at specified positions, bb (0b1000)(0 \le b \le 1000) is the number of hints on repeated substrings, and qq (1q1000)(1 \le q \le 1000) is the number of positions asked.

The ii-th of the following aa lines contains an integer xix_i and an uppercase letter cic_i, meaning that the letter at position xix_i of the secret string is cic_i. These hints are ordered by position, that is 1x1<<xan1 \le x_1 < \cdots < x_a \le n.

The ii-th of the following bb lines contains two integers yiy_i and hih_i. It is guaranteed that 2y1<<ybn2 \le y_1 < \cdots < y_b \le n and 0hi<yi0 \le h_i < y_i. When hih_i is not 0, the substring of the secret string starting at position yiy_i with length yi+1yiy_{i+1} - y_i (with length n+1yin + 1 - y_i when i=bi = b) equals the substring of the same length starting at position hih_i. A line with hi=0h_i = 0 tells nothing except that the substring specified in the line immediately above ends just before position yiy_i.

The ii-th of the following qq lines contains an integer ziz_i (1zin)(1 \le z_i \le n), the position of the letter to output.

At least one secret string matching all the given information exists. In other words, the hints have no contradiction.

Output

Print a single line of qq characters. The ii-th character of the output is the letter at position ziz_i of the secret string when the hints decide it uniquely, and a question mark ? otherwise.