Semi-Case-Insensitive Search
InterviewTime limit2sMemory limit1024 MB
Given item names and queries, report for each query whether it matches an item, ignoring letter case only when that item is always written the same way in the list.
Problem
Recently, a company where Vasya works held an inventory check. Many items were found that are not needed for daily work but could be useful in some situations, such as an artificial spruce, a hockey puck, balloons, and more. They were all put in a storage room, a dusty and dark place. Nobody wants to go in there every time to look for an item that may not be there. To solve this, the boss ordered a program that takes an item name and reports whether it is in the storeroom. Vasya was assigned the job and received the list of items in storage.
At first Vasya thought the task was too simple. Then he found an unpleasant feature. To keep notation short, people used letter case to show the size of an item. For example, inflatable balloons were written as "шар", "Шар", "ШАР", or "шаР". Someone searching for "ШАР" is probably looking for large balloons. On the other hand, some names were never written with such variations. So if someone searches for "Диван", a list that only has "диван" should still give a positive answer.
After hours of thinking, Vasya decided on this rule. If a name is written the same way everywhere in the list, the program answers positively even when some letters' cases in the query differ. Otherwise, the program checks whether the list contains exactly that name with exactly the same case for every letter. Unfortunately, Vasya's computer broke, and he asks you to help him write this program.
Input
The first line contains an integer (), the number of items in the list. The next lines each contain one item name. The next line contains an integer (), the number of queries. Each of the next lines contains one query word. All item names consist of uppercase and lowercase Latin letters, and each is at most 20 characters long.
Output
The output must contain one line. For each query, print "+" if the answer is positive and "-" otherwise.