The first line of input contains two integers $n$ and $k$, where $n(1 \le n \le 10^6)$ is the total number of Royal Ladies and $k(1 \le k \le10^6)$ is the number of query strings.
Then follow $n$ lines describing the Royal Ladies. The $i^\text{th}$ of these lines describes the Royal Lady numbered $i$, and contains an uppercase letter $c_i$ (‘A’–‘Z’) and an integer $p_i$, where $c_i$ is the first letter of the name of Lady $i$, and $p_i(p_1=0$ and $1 \le p_i <i$ for $i>1)$ is the number of her mother (or $0$, in the case of the First Lady). All the names are unique.
The remaining $k$ lines each contain one nonempty query string, consisting only of uppercase letters. The sum of the lengths of the query strings is at most $10^6$.