Circular String

3rd DIU-SWE Intra Departm...
Limits 1s, 512 MB

A Circular String is a string that does not have an initial or terminal element. Instead, the two ends of the string are joint together and string can be viewed as a necklace.

In this problem, you will be given a circular string and Q queries.

In each query, a normal string will be given and you to find if this string is
present in the circular string or not.

Remember in input circular string will be represented as a normal string but you have to assume it as a circular string.

The input string will be given as clock-wise order. The first and last element of the given string is connected together. For example, if abcde is a circular string then the first element of this circular string "a" and the last element of this circular string "e" are joint together.

Input

The first line contains a string S. S is the circular string. S will contain only lowercase English letters.

The next line contains an integer, the number of queries Q (1<=Q<=100).
In each query, you will be given a string M.

1<=|S|,|M|<=1000.

Here, |S| and |M| are the lengths of the strings S and M.

Output

For each query, if the query string in present in the circular string, you have to print "Yes", otherwise "No".

Sample

InputOutput
abdefh
5
abdefh
fha
dbah
habdef
bdefhab
Yes
Yes
No
Yes
No

Submit

Login to submit.

Statistics

78% Solution Ratio
Mehedi_MithunEarliest, Apr '19
emrul_muFastest, 0.0s
Mehedi_MithunLightest, 131 kB
shantanu404Shortest, 167B
Toph uses cookies. By continuing you agree to our Cookie Policy.