#K39192. Find Name Indices

    ID: 26366 Type: Default 1000ms 256MiB

Find Name Indices

Find Name Indices

You are given a list of names and a list of name queries. For each query, your task is to determine the 1-indexed position of the name in the list. If the name does not exist in the list, output -1.

Task: For each queried name, find its index (starting from 1) in the provided list of names. If the name is not present, print -1.

Note: Names can include spaces and consist of a first name and a last name. Use an efficient lookup if possible.

Example:

Input:
5
alice smith
john doe
jane austen
emma woodhouse
charlotte bronte
3
john doe
mr darcy
emma woodhouse

Output: 2 -1 4

</p>

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer n, the number of names.
  • The next n lines each contain a name (a string that may contain spaces).
  • The following line contains a single integer q, the number of queries.
  • The next q lines each contain a query name.

outputFormat

For each query, output the 1-indexed position of the name in the list if it exists; otherwise, output -1. The results should be printed in one line separated by spaces to stdout.

## sample
5
alice smith
john doe
jane austen
emma woodhouse
charlotte bronte
3
john doe
mr darcy
emma woodhouse
2 -1 4