Shortest Missing Subsequences

아직 제출이 없습니다시간 제한10초메모리 제한1024 MB

문제

Given a string ss we say that string tt is a Subsequence of ss if tt can be obtained from ss by deleting zero or more characters of ss. Note that tt is not necessarily a substring of ss---that is, tt is not necessarily contiguous in ss, but the characters of tt appear in the same order as they do in ss.

For a given subset, vv, of the lowercase English alphabet characters from 'a' to 'z', we say that string uu is a Missing Subsequence of another string ss if uu is not a Subsequence of ss, but all characters in uu and all the characters of ss are in the set vv. A Shortest Missing Subsequence of ss is a Missing Subsequence of ss with the smallest length among all Missing Subsequences of ss.

Given a set of English alphabetic characters, a target string made up of characters from that set, and a list of query strings made up of characters from that set, determine if each of the query strings is a Shortest Missing Subsequence of the target string.

입력

The first line of input contains a string vv (1v261 \le |v| \le 26) of lowercase letters, in lexicographical order. Each letter appears at most once. This is the set of alphabetic characters.

The next line of input contains a string ss (1s1061 \le |s| \le 10^6, ss only contains letters from vv). This is the target string to be queried.

The next line contains an integer nn (1n1061 \le n \le 10^6). This is the number of queries.

Each of the next nn lines contains a string qq (1q1061 \le |q| \le 10^6, qq only contains letters from vv). These are the query strings. The sum of the lengths of all query strings will not exceed 10610^6.

출력

Output nn lines, one for each query. On each line, output either 11 if the query string is a Shortest Missing Subsequence of the target string, or 00 if it is not. The outputs must be in the order of the input queries.