Limits 1s, 512 MB

The government wants to provide relief to the flood-affected people. So, it set a committee. The committee has created a function FF to count the number of affected people.

Suppose, the country has nn divisions A1,A2,A3AnA_1, A_2, A_3……A_n. A1A_1 means the first division has A1A_1 districts. A2A_2 means the second division has A2A_2 districts.

In general, AiA_i means the ithi_{th} division has AiA_i districts.

They defined the function F such that F(i)=XYF(i) = \frac{X}{Y} where X=j=1,ijnAjX = {\prod_{j = 1, i \neq j}^{n}A_j}, Y=Ai2Y = A_{i}^{2}. It means the ithi_{th} division has (Fi)\left \lfloor (F_i) \right \rfloor affected people.

If they wanted to do the calculation by hand, it would have taken a lot of time. So, they decided to create a robot. If they give the robot, nn, (A1,A2,,AnA_1,A_2, …, A_n), mm and (B1,B2,,BmB_1,B_2, …, B_m), the robot returns j=1mF(Bj)\sum_{j=1}^{m}\left \lfloor F(B_j) \right \rfloor.

As they are not experts, the robot has some errors. It can calculate a number x if and only if x[0,109]x ∈ [0,10^{9}] and it calculates the numerator first and then divide it with denominator.

If it takes a number Y and can’t calculate F(Y)F(Y), it assumes that F(Y)=0F(Y) = 0. But as the committee members are not sure whether the robot works properly, they hired you as you are an expert mathematician. Can you help them?

In the problem:

  • \prod means Pi function.

  • X\left \lfloor X \right \rfloor means floor function. It returns the largest integer that is smaller than or equal to XX.

  • \sum means Sigma function.

It is guaranteed that j=1mF(Bj)[0,109]\sum_{j=1}^{m}\left \lfloor F(B_j) \right \rfloor ∈ [0,10^{9}].

Input

Input starts with an integer TT (T100T \le 100), denoting the number of test cases. The first line of each test case contains one integer nn (2n302 \le n \le 30) the number of divisions in the country. The second line of each test case contains nn integers A1,A2,A3AnA_1, A_2, A_3……A_n (0Ai1000 \le A_i \le 100), where AiA_i is the number of districts in ithi_{th} division.

The third line of each test case contains one integer mm (mnm \le n). The fourth line of each test case contains mm integers B1,B2,B3BmB_1, B_2, B_3……B_m. All indices are 1-based.

Output

For each case print the case number and the the value of j=1mF(Bj)\sum_{j=1}^{m}\left \lfloor F(B_j) \right \rfloor.

Sample

InputOutput
1
10
100 10 10 10 10 10 10 10 10 10
2
1 2
Case #1: 100000

Here, m=2m=2, B1=1B1 = 1 and B2=2B2 = 2

Now, suppose F(B1)=XYF(B1) = \frac{X}{Y}

X=a2×a3×a4××a10=1000000000X = a_2 \times a_3 \times a_4 \times … \times a_{10} = 1000000000

and Y=(1002)=10000Y = (100^{2}) = 10000

then XY=100000000010000=100000\frac{X}{Y} = \frac{1000000000}{10000} = 100000

So F(B1)=100000F(B1) = 100000

Again F(B2)=XYF(B2) = \frac{X}{Y}

X=a1×a3×a4××a10=1010X = a_1 \times a_3 \times a_4 \times … \times a_{10} = 10^{10}

As XX not belongs to [0,109][0,10^{9}], it cant calculate XX

So robot assumes that F(B2)=0F(B2) = 0

So the final answer is F(B1)+F(B2)=100000+0=100000F(B1)+F(B2) = 100000+0 = 100000


Submit

Login to submit.

Statistics

77% Solution Ratio
Dipra_IrhamEarliest, Oct '20
Exo_TicFastest, 0.0s
Tanjim54Lightest, 0 B
Tahmid690Shortest, 607B
Toph uses cookies. By continuing you agree to our Cookie Policy.