You are given N strings, namely S1,S2,…,SN.
M other strings will be constructed as a concatenation of other strings. More specifically, the ith (N+1≤i≤N+M) string Si will be constructed as a concatenation of several other strings Sk, where 1≤k≤i−1.
You must answer Q queries consisting of an index i (1≤i≤N+M) and an integer p (1≤p≤min(|Si|,250); you must print the pth character of Si.
Input
The first line contains two integer N and M.
The next N+M lines describe S1,S2,…,SN+M.
The first N lines consist of actual strings S1,S2,...,SN.
The next M lines describe the construction of SN+1,SN+2,…,SN+M. Every line i (1≤i≤M) consists of an integer ki and ki indices qi1,qi2,…,qiki, meaning that Si+N=Sqi1+Sqi2+…+Sqiki, where + is the string concatenation operator.
The next line contains an integer Q.
Each of the following Q lines consist of two integers i and p.
Output
Print a string of Q characters, in which the ith character represents the answer for the ith query.
Notes
S6="abcdddqxxasfqscedv" and S7="qscedvddd"
In the first query we must print the 3rdcharacter of S1.