P9738 [AOJ] Lottery Checker
普及
题目描述

You have successfully completed your studies and are preparing to move from near Komaba to near Hongo. As I was organizing my house, I found a lot of lottery tickets I bought last year. After confirming the exchange deadline, I have to cash in by tomorrow, but it is troublesome to go to the lottery counter for a small amount of money because I am not ready to move at all. So you decide to find out how much you can win.

The lottery consists of eight digits. The winning number is also composed of 8 digits and a number and'*', and if the lottery you have and the number part match, the winning money will be paid according to the winning number.

For example, if the lottery number you have is "12345678", you will win if the winning number is "* 8" or "* 5678", but the winning number is "*". If it is ** 4678 ", you will not win. There can be multiple winning numbers, and the winnings will be paid independently for each. However, the winning numbers are chosen so that one lottery does not win more than one winning number. For example, if there are two winning numbers, "* 8" and "** 5678", "12345678" will win both, so such a winning number will be selected. There is no one to be done.

Your job is to write a program that outputs how much winning money you will get for the lottery number you have and the lottery winning number given as input.

Notes on Test Cases

Multiple datasets are given in the above input format. Create a program that outputs each data set in the above output format.

When n is 0, it indicates the end of input.

输入格式

见题面

输出格式

见题面

样例输入
3 3 *******1 100 ******22 1000 11111112 1000000 01203291 02382022 11111111 10 10 ****3228 149416 ****3992 198635 ****4286 77783 ****4843 225244 ***49835 231046 ***59393 379996 *5763748 437345 *6726222 58054 *8117882 16375 *9244339 537727 77885716 96726222 26971031 66652868 89599648 37772338 64679621 65479161 92959393 57855682 0 0
样例输出
1200 438050