#B3672. Library Book Code Matching

    ID: 11331 Type: Default 1000ms 256MiB

Library Book Code Matching

Library Book Code Matching

In a library, every book is assigned a unique positive integer as its book code, and each borrower possesses a demand code which is also a positive integer. A book is considered to be the one a borrower needs if its book code ends with the borrower's demand code. Formally, for a given book code (a) and a demand code (b), the book is counted if (a) ends with (b) (i.e., (b) is a suffix of (a)).

Given the list of book codes in the library and several readers' demand codes, your task is to determine, for each reader, how many books satisfy this condition.

inputFormat

The first line contains an integer (n) denoting the number of books. The second line contains (n) positive integers representing the book codes. The third line contains an integer (q) representing the number of readers. Each of the following (q) lines contains a positive integer that is the reader's demand code.

outputFormat

For each demand code, output a single integer which is the count of books whose code ends with that demand code.

sample

5
123 456 334 12345 345
3
3
45
456
1

2 1

</p>