The first line contains an integer N (1 ≤ N ≤ 30000), the number of words in the database.
Each of the following N lines contains a single word from the database. The words are given in the order the algorithm compares them to a query word. All words in the database will be distinct.
The following line contains an integer Q (1 ≤ Q ≤ 30000), the number of words searched for.
Each of the following Q lines contains a single query word.
All words in the input will be strings of less than 30 lowercase letters of the English alphabet.
Time Limit: 2 seconds
Output one integer per line for each query word, the number of steps the algorithm uses when searching for the word.
Divisible Substrings
Ninja and Numbers
Longest Palindromic Substring
Cakes
1-3 Palindrome