{"raw_statement":[{"iden":"problem statement","content":"There are $N$ strings of lowercase alphabet only. The $i$\\-th string is $S_i$. Every string is unique.\nProvide answers for the $Q$ queries below. The $i$\\-th query has the following format:\nQuery: An integer $k_i$ and a string $p_{i,1}p_{i,2}...p_{i,26}$ that results from permuting {`a`$,$`b`$,...,$`z`} are given. Output the sequence of the string $S_{k_i}$ among the $N$ strings in lexicographical order when the literal sequence is $p_{i,1}<p_{i,2}<...<p_{i,26}$."},{"iden":"constraints","content":"*   $1 ≦ N,Q ≦ 100000$\n*   $1 ≦ |S_i| (1 ≦ i ≦ N)$\n*   $S_i (1 ≦ i ≦ N)$ is a string of lowercase alphabet.\n*   The sum of $|S_i|$ is no more than $400000$.\n*   Every $S_i$ is unique.\n*   $1 ≦ k_i ≦ N (1 ≦ i ≦ Q)$\n*   For all $1 ≦ i ≦ Q$, $p_{i,1}p_{i,2}...p_{i,26}$ is a permutation of `abcd...z`."},{"iden":"input","content":"Inputs are provided from standard inputs in the following form.\n\n$N$\n$S_1$\n:\n$S_N$\n$Q$\n$k_1$ $p_{1,1}p_{1,2}...p_{1,26}$\n:\n$k_Q$ $p_{Q,1}p_{Q,2}...p_{Q,26}$"},{"iden":"sample input 1","content":"5\naa\nabbaa\nabbba\naaab\naaaaaba\n5\n1 abcdefghijklmnopqrstuvwxyz\n2 bacdefghijklmnopqrstuvwxyz\n3 abcdefghijklmnopqrstuvwxyz\n4 bacdefghijklmnopqrstuvwxyz\n5 abcdefghijklmnopqrstuvwxyz"},{"iden":"sample output 1","content":"1\n2\n5\n4\n2\n\nWhen the literal sequence is `a` $<$ `b`, sorting the input strings in lexicographical order yields `aa`, `aaaaaba`, `aaab`, `abbaa`, `abbba`. The answers to queries $1$, $3$, and $5$ are thus $1$, $5$, and $2$, respectively.\nWhen the literal sequence is `b` $<$ `a`, sorting the input strings in lexicographical order yields `abbba`, `abbaa`, `aa`, `aaab`, `aaaaaba`. The answers to queries $2$ and $4$ are thus $2$ and $4$, respectively."},{"iden":"sample input 2","content":"8\nabrakatabra\nabadaba\nabracadabra\natcoder\ngrand\ncontest\nababa\na\n6\n3 abcdefghijklmnopqrstuvwxyz\n6 qwertyuiopasdfghjklzxcvbnm\n8 poiuytrewqlkjhgfdsamnbvcxz\n2 qazwsxedcrfvtgbyhnujmikolp\n1 plokmijnuhbygvtfcrdxeszwaq\n4 mnbvcxzasdfghjklpoiuytrewq"},{"iden":"sample output 2","content":"4\n8\n2\n3\n4\n7"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}