Write a program that computes the prize money of a Thai government lottery ticket. A ticket number has six digits. Six prizes are checked: one first prize, two front three digit prizes, two last three digit prizes, and one last two digit prize.

A ticket wins each prize under these conditions.
When one ticket wins several prizes, add every prize it wins. If two prizes have the same winning number, the ticket receives both.
The first six lines each hold a winning number and a prize amount separated by a space. The order is the first prize, the two front three digit prizes, the two last three digit prizes, and the last two digit prize. The first prize number has six digits, the front three digit and last three digit numbers have three digits, and the last two digit number has two digits. Leading zeros are written out. Each prize amount is an integer between 1 and 109.
From the seventh line on, each line holds one six digit ticket number to check. A line containing only -1 ends the input. There are at most 100,000 ticket numbers.
For each ticket, in input order, print on its own line the total prize money that ticket receives.