Under construction

Still being built. Things may change

Languages

Time limit2sMemory limit1024 MB

Summary
Given names for digits 0 to 9, find for each number the digit in it whose name comes last in alphabetical order.
Level

Easy2 of 10

Topics
String, Implementation
Solved
No attempts yet

Problem

Fedor decided to learn a new language and started by memorizing the names of the digits. To check what he has learned, he picks a number and finds the digit in it whose name comes last in alphabetical order. Fedor is not fully sure of his knowledge yet, so he needs a checker.

Word aa comes before word bb in alphabetical order if either aa is a prefix of bb, or the two words share their first few characters (possibly none) and the next character of aa comes before the corresponding character of bb in the alphabet.

Write a program that helps Fedor check his answers. A number is given. Find the digit in it whose name comes last in alphabetical order, compared with the names of the other digits. The digit names are given in the input file.

Input

The first line contains the names of the digits from 00 to 99 in the language Fedor is learning, separated by spaces. Each name is nonempty and consists of at most 50 lowercase Latin letters.

The second line contains nn (1≤n≤10001 \le n \le 1000). The next nn lines each contain a number aia_i for which Fedor wants the answer (0≤ai≤1090 \le a_i \le 10^9, with no leading zeros).

Output

On the ii-th line, print one word: the name of the digit that appears in aia_i and comes last in alphabetical order.

Examples2

  1. Example 1

    Input
    nulo unu du tri kvar kvin ses sep ok nau
    3
    123
    456
    908
    
    Expected output
    unu
    ses
    ok
    
  2. Example 2

    Input
    zero un deux trois quatre cinq six sept huit neuf
    3
    123
    456
    908
    
    Expected output
    un
    six
    zero