Baby Ming and phone number

Accepts: 111
Submissions: 878
Time Limit: 3000/1500 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description

Baby Ming collected lots of cell phone numbers, and he wants to sell them for money.

He thinks normal number can be sold for bb yuan, while number with following features can be sold for aa yuan.

1.The last five numbers are the same. (such as 123-4567-7777)

2.The last five numbers are successive increasing or decreasing, and the diffidence between two adjacent digits is 11. (such as 188-0002-3456)

3.The last eight numbers are a date number, the date of which is between Jar 1st, 1980 and Dec 31th, 2016. (such as 188-1888-0809,means August ninth,1888)

Baby Ming wants to know how much he can earn if he sells all the numbers.

Input

In the first line contains a single positive integer TT, indicating number of test case.

In the second line there is a positive integer nn, which means how many numbers Baby Ming has.(no two same phone number)

In the third line there are 22 positive integers a,ba, b, which means two kinds of phone number can sell aa yuan and bb yuan.

In the next nn lines there are nn cell phone numbers.(|phone number|==11, the first number can’t be 0)

1T30,b<1000,0<a,n100,0001 \leq T \leq 30, b < 1000, 0 < a, n \leq 100,000

Output

How much Baby Nero can earn.

Sample Input
1
5
100000 1000
12319990212
11111111111
22222223456
10022221111
32165491212
Sample Output
302000