Hari Merdeka

No attempts yetTime limit3sMemory limit256 MB

Problem

Malaysia's Independence Day is called Hari Merdeka. It falls on 31 August every year and marks the independence of the Federation of Malaya from British colonial rule in 1957. Through the whole month of August many Malaysians raise the national flag on the balcony of their home and on every vehicle they own, baby strollers included. At the celebration people shout "Merdeka!" seven times.

For next year's Independence Day, IIUM will hang a long banner around its main campus. The organising committee wants to write words on the banner that encourage the students and the professors. Two rules apply. All words go on one single line with no spaces between them. Words are allowed to overlap each other. For example, WORDER contains the words WORD and ORDER. Whatever ends up on the banner is called the text.

The committee compiled a list of words and gave each word a score. The score of the text is the sum of the score of each word once for every occurrence of that word in the text. If WORD is worth 5 and ORDER is worth 8, then the text WORDER scores 5+8=135 + 8 = 13. In the text WORDWORDER the word WORD occurs twice, so it scores 5+5+8=185 + 5 + 8 = 18.

The committee also wants every character in the text handcrafted. Crafting one character costs money and the committee's budget is fixed.

Find the text with the highest score whose cost stays within the budget. Do not print the text itself, only its score.

Input

The first line contains an integer TT, the number of cases. (T30T \le 30)

Each case starts with a line holding three integers NN, MM and BB: the number of characters, the number of words, and the committee's budget. (1<N261 < N \le 26, 1M1001 \le M \le 100, 10B20010 \le B \le 200)

The next NN lines each contain one character HiH_i from A to Z and one integer CiC_i, the cost of writing one HiH_i in the text. (1Ci31 \le C_i \le 3) All HiH_i are distinct.

The following MM lines each contain one word WiW_i and one integer SiS_i, the score of that word. (1Wi1001 \le |W_i| \le 100, 1Si1001 \le S_i \le 100)

Every character used in the words appears among the HiH_i. The text may use only those NN characters, and the cost of the text is the sum of the cost of every character written in it.

Output

For each case print one line in the form Case #X: Y, where XX is the case number starting from 1 and YY is the highest score obtainable in that case. If no text within the budget contains any word, print 0.

Hint

In the first case of the first example the best text is AAAAA. It contains AA four times and AAA three times, so the score is 4×10+3×30=1304 \times 10 + 3 \times 30 = 130. Writing AAAAA needs five copies of A at a cost of 2 each, so the total cost is 10.