Problem: Problem J String Puzzle

Amazing Coding Magazine is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try!

The puzzle in the latest issue is on deciding some of the letters in a string (the secret string, in what follows) based on a variety of hints. The figure below depicts an example of the given hints.

<image>

The first hint is the number of letters in the secret string. In the example of the figure above, it is nine, and the nine boxes correspond to nine letters. The letter positions (boxes) are numbered starting from 1, from the left to the right.

The hints of the next kind simply tell the letters in the secret string at some speci c positions. In the example, the hints tell that the letters in the 3rd, 4th, 7th, and 9th boxes are C, I, C, and P

The hints of the final kind are on duplicated substrings in the secret string. The bar immediately below the boxes in the figure is partitioned into some sections corresponding to substrings of the secret string. Each of the sections may be connected by a line running to the left with another bar also showing an extent of a substring. Each of the connected pairs indicates that substrings of the two extents are identical. One of this kind of hints in the example tells that the letters in boxes 8 and 9 are identical to those in boxes 4 and 5, respectively. From this, you can easily deduce that the substring is IP.

Note that, not necessarily all of the identical substring pairs in the secret string are given in the hints; some identical substring pairs may not be mentioned.

Note also that two extents of a pair may overlap each other. In the example, the two-letter substring in boxes 2 and 3 is told to be identical to one in boxes 1 and 2, and these two extents share the box 2.

In this example, you can decide letters at all the positions of the secret string, which are "CCCIPCCIP". In general, the hints may not be enough to decide all the letters in the secret string.

The answer of the puzzle should be letters at the specified positions of the secret string. When the letter at the position specified cannot be decided with the given hints, the symbol ? should be answered.

Input

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


$n$ $a$ $b$ $q$
$x_1$ $c_1$
...
$x_a$ $c_a$
$y_1$ $h_1$
...
$y_b$ $h_b$
$z_1$
...
$z_q$


The first line contains four integers $n$, $a$, $b$, and $q$. $n$ ($1 \leq n \leq 10^9$) is the length of the secret string, $a$ ($0 \leq a \leq 1000$) is the number of the hints on letters in specified positions, $b$ ($0 \leq b \leq 1000$) is the number of the hints on duplicated substrings, and $q$ ($1 \leq q \leq 1000$) is the number of positions asked.

The $i$-th line of the following a lines contains an integer $x_i$ and an uppercase letter $c_i$ meaning that the letter at the position $x_i$ of the secret string is $c_i$. These hints are ordered in their positions, i.e., $1 \leq x_1 < ... < x_a \leq n$.

The $i$-th line of the following $b$ lines contains two integers, $y_i$ and $h_i$. It is guaranteed that they satisfy $2 \leq y_1 < ... < y_b \leq n$ and $0 \leq h_i < y_i$. When $h_i$ is not 0, the substring of the secret string starting from the position $y_i$ with the length $y_{i+1} - y_i$ (or $n+1-y_i$ when $i = b$) is identical to the substring with the same length starting from the position $h_i$. Lines with $h_i = 0$ does not tell any hints except that $y_i$ in the line indicates the end of the substring specified in the line immediately above.

Each of the following $q$ lines has an integer $z_i$ ($1 \leq z_i \leq n$), specifying the position of the letter in the secret string to output.

It is ensured that there exists at least one secret string that matches all the given information. In other words, the given hints have no contradiction.

Output

The output should be a single line consisting only of $q$ characters. The character at position $i$ of the output should be the letter at position $z_i$ of the the secret string if it is uniquely determined from the hints, or ? otherwise.

Sample Input 1


9 4 5 4
3 C
4 I
7 C
9 P
2 1
4 0
6 2
7 0
8 4
8
1
9
6


Sample Output 1


ICPC


Sample Input 2


1000000000 1 1 2
20171217 A
3 1
42
987654321


Sample Output 2


?A






Example

Input

9 4 5 4
3 C
4 I
7 C
9 P
2 1
4 0
6 2
7 0
8 4
8
1
9
6


Output

ICPC

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, a, b, q;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> a >> b >> q;
	vector<pair<int, char>> xs;
	rep(i, a){ int x; char c; cin >> x >> c; xs.emplace_back(--x, c); }
	
	vector<pi> ys;
	rep(i, b){ int y, h; cin >> y >> h; ys.emplace_back(--y, --h); }
	if(ys.size() && ys.back().second >= 0) ys.emplace_back(n, -1);
	
	map<pi, int> left;
	rep(i, ys.size()){
		if(ys[i].second < 0) continue;
		int L = ys[i].first, R = ys[i + 1].first;
		int l = ys[i].second, r = l + R - L, d = L - l;
		left[pi(L, R)] = d;
	}
	
	auto move = [&](int p){
		map<pi,int>::iterator it = left.lower_bound(pi(p + 1, 0));
		if(it == left.begin()) return p;
		--it;
		
		if(!(it->first.first <= p && p < it->first.second)) return p;
		int l = it->first.first - it->second, t = (p - l) / it->second;
		return p - t * it->second;
	};
	
	unordered_map<int, char> cs;
	for(auto i : xs){
		int p = i.first;
		for(int nxt = p; p != (nxt = move(p)); p = nxt);
		cs[p] = i.second;
	}
	/*
	for(auto p : cs) dbg(p.first, p.second);
	for(auto p : left) dbg(p.first, p.second);
	*/
	string ans;
	while(q--){
		int p; cin >> p;
		for(int nxt = --p; p != (nxt = move(p)); p = nxt);
		ans += cs.count(p) ? cs[p] : '?';
	}
	cout << ans << endl;
	return 0;
}