#Lutece1220. The Battle of Guandu

The Battle of Guandu

Migrated from Lutece 1220 The Battle of Guandu

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

In the year of 200200, two generals whose names are Cao Cao and Shao Yuan are fighting in Guandu. The battle of Guandu was a great battle and the two armies were fighting at MM different battlefields whose numbers were 11 to MM. There were also NN villages nearby numbered from 11 to NN. Cao Cao could train some warriors from those villages to strengthen his military. For village ii, Cao Cao could only call for some number of warriors join the battlefield xix_i. However, Shao Yuan's power was extremely strong at that time. So in order to protect themselves, village ii would also send equal number of warriors to battlefield yiy_i and join the Yuan Shao's Army. If Cao Cao had called for one warrior from village ii, he would have to pay cic_i units of money for the village. There was no need for Cao Cao to pay for the warriors who would join Shao Yuan's army. At the beginning, there were no warriors of both sides in every battlefield.

As one of greatest strategist at that time, Cao Cao was considering how to beat Shao Yuan. As we can image, the battlefields would have different level of importance wiw_i. Some of the battlefields with wi=2w_i = 2 were very important, so Cao Cao had to guarantee that in these battlefields, the number of his warriors was greater than Shao Yuan's. And some of the battlefields with wi=1w_i = 1 were not as important as before, so Cao Cao had to make sure that the number of his warriors was greater or equal to Shao Yuan's. The other battlefields with wi=0w_i = 0 had no importance, so there were no restriction about the number of warriors in those battlefields. Now, given such conditions, could you help Cao Cao find the least number of money he had to pay to win the battlefield?

Input

The first line of the input gives the number of test cases, TT(1T301\leq T\leq 30). TT test cases follow.

Each test case begins with two integers NN and MM(1N,M1051\leq N, M\leq 10^5) in one line.

The second line contains NN integers separated by blanks. The ithi_{th} integer xix_i(1xiM1\leq x_i\leq M) means Cao Cao could call for warriors from village ii to battlefield xix_i.

The third line also contains NN integers separated by blanks. The ithi_{th} integer yiy_i(1yiM1\leq y_i\leq M) means if Cao Cao called some number of warriors from village ii, there would be the same number of warriors join Shao Yuan's army and fight in battlefield yiy_i.

The next line contains NN integers separated by blanks. The ithi_{th} integer cic_i(0ci1050\leq c_i\leq 10^5) means the number of money Cao Cao had to pay for each warrior from this village.

The last line contains MM integers separated by blanks. The ithi_{th} number wiw_i(wi{0,1,2}w_i\in \{0, 1, 2\}) means the importance level of ithi_{th} battlefield.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy is the least amount of money that Cao Cao had to pay for all the warriors to win the battle. If he couldn't win, y=1y = -1.

Samples

2
2 3
2 3
1 1
1 1
0 1 2
1 1
1
1
1
2
Case #1: 1
Case #2: -1

Resources

The 2015 China Collegiate Programming Contest