### Gene

Time Limit: 1000 ms Memory Limit: 65536 KiB

#### Problem Description

How can millions of different and complex structures be built using only a few simple building blocks? Just ask your DNA. DNA (short for deoxyribonucleic acid) spells out the genetic codes of millions of species, using just four molecules: adenine (A), guanine (G), thymine (T), and cytosine (C). These molecules are called nucleotide bases. Different sequences of nucleotide bases are what define each species.
Within this coil of DNA lies all the information needed to produce everything in the human body. A strand of DNA may be millions, or billions, of base-pairs long. Different segments of the DNA molecule code for different characteristics in the body. A Gene is a relatively small segment of DNA that codes for the synthesis of a specific protein. This protein then will play a structural or functional role in the body. A chromosome is a larger collection of DNA that contains many genes and the support proteins needed to control these genes
Now , we give you the Sequence of some genes, which code for different proteins. And then we give every protein a score.here comes your problem,if we give you a chromosome in sequence , of course it can code many proteins, can you arrange which proteins it code , with the object to get The largest score (two proteins can not be overlap).

#### Input

There will be several testcases. For each testcase, the first line is an integer N(1 < N ≤ 100,000), the number of the genes we will give you. Then followed N lines , each line contains a string S(the lenth of S is no more than 10), the sequence of the gene , and an integer C, the score of the protein the gene code. The last line of each testcase is a string (the length of this string is no more than 1000), describes the sequence of the chromosome.

#### Output

For each testcase , output the largest score in the sample’s format.

#### Sample Input

4
AATG 3
AT 2
GCGG 3
GG 2
AATGCGG
3
A 1
C 1
G 1
T

#### Sample Output

Case 1: 5
Case 2: 0

2009湖南大学校赛