{"problem":{"name":"Lexicographical disorder","description":{"content":"There are $N$ strings of lowercase alphabet only. The $i$\\-th string is $S_i$. Every string is unique. Provide answers for the $Q$ queries below. The $i$\\-th query has the following format: Query: An ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":6000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"codefestival_2016_qualB_e"},"statements":[{"statement_type":"Markdown","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}$.\n\n## Constraints\n\n*   $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`.\n\n## Input\n\nInputs 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}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"codefestival_2016_qualB_e","tags":[],"sample_group":[["5\naa\nabbaa\nabbba\naaab\naaaaaba\n5\n1 abcdefghijklmnopqrstuvwxyz\n2 bacdefghijklmnopqrstuvwxyz\n3 abcdefghijklmnopqrstuvwxyz\n4 bacdefghijklmnopqrstuvwxyz\n5 abcdefghijklmnopqrstuvwxyz","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."],["8\nabrakatabra\nabadaba\nabracadabra\natcoder\ngrand\ncontest\nababa\na\n6\n3 abcdefghijklmnopqrstuvwxyz\n6 qwertyuiopasdfghjklzxcvbnm\n8 poiuytrewqlkjhgfdsamnbvcxz\n2 qazwsxedcrfvtgbyhnujmikolp\n1 plokmijnuhbygvtfcrdxeszwaq\n4 mnbvcxzasdfghjklpoiuytrewq","4\n8\n2\n3\n4\n7"]],"created_at":"2026-03-03 11:01:14"}}