TOP10 - Top 10

no tags 

Given a dictionary containing less than N = 20000 words labeled from 1 to N. Each word consists of lowercase characters (from 'a' to 'z') with arbitrary length. The total number of characters in the dictionary is at most 100,000.

Your task is to answer at most Q = 100000 queries. Each query qi is also a word (as defined above). For each query, you have to print the "Top 10" words in the dictionary with the following rules:

  • All the words in the "Top 10" have to contain the substring qi.
  • All the words in the "Top 10" have to be sorted in this order:
    1. The words with shorter length come first, if they have equal length then
    2. The lexicographically smaller words come first, otherwise
    3. The words with smaller label come first.

If the number of words in the dictionary that contains the substring qi is less than 10 then print all the words otherwise, print only the top 10 words (note: the words are printed using their labels).

If there is no word in the dictionary that contains the substring qi then print "-1" (without the quotes).

Input

The first line contains the number N. The next N lines contains the N words in the dictionary (the ith line is the word with label i). The next line contains the number Q followed by the Q lines containing the queries.

Output

For each query, print one line containing the labels of the "Top 10" words (separated by a space) in the dictionary using the rules defined above.

Example

Input:
17
acm
icpc
regional
asia
jakarta
two
thousand
and
nine
arranged
by
universitas
bina
nusantara
especially
for
you
5
a
an
win
b
z

Output:
1 8 4 13 5 10 3 7 14 15
8 10 7 14
-1
11 13
-1

hide comments
ymGXX: 2010-10-03 09:57:38

There is some problems about my program(sometimes TLE).But I still have got AC.

Ashish Khurange: 2010-03-26 20:10:22

Why C++ 4.3.2 is not allowed??


Added by:VOJ problem setters
Date:2009-10-28
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 C++ 4.3.2 NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Problem Setter: Felix Halim
ACM ICPC - Jakarta 2009