Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Modulo

By Hasinur_ · Limits 4s, 512 MB

Let's get straight into the problem. In ths problem, here will be multiple test cases. In each test case you will be given an array AA of NN integers. Then there will be QQ queries. In each query You will be given an integer MM. For every ii where 1iN1 \le i \le N you have to change A[i]A[i] to A[i]A[i] mod MM. After executing all queries you have to print the array AA in the order of input.

Note that you have to execute QQ queries in the order of input.

Input

Input will start with a single integer TT (1T1051 \le T \le 10^5), denoting the number of test cases.

For each test case, the first line will contain an integer NN (1N1051 \le N \le 10^5). NN is the size of the array AA.

Second-line will contain NN space-separated integers in the range [1,260][1, 2^{60}].

Third line will contain an integer QQ (1Q1051 ≤ Q ≤ 10^5). QQ is the number of queries. Fourth line will contain QQ integers in the range [1,261][1, 2^{61}]. Each of the QQ integers are the MM explained in the statement.

It is guaranteed that sum of total NN over all test cases doesn't exceed 500000 and the sum of total QQ over all test cases doesn't exceed 500000.

Output

For each test case print "Case x:" in a line without quotations where x is the test case number.

Then print the elements of array AA separated by spaces. See sample input-output for better understanding.

Sample

InputOutput
2
2
4 4
1
2
3
8 4 8
1
2
Case 1:
0 0
Case 2:
0 0 0

Discussion

Statistics


68% Solution Ratio

aniks2645Earliest, Oct '19

prodip_bsmrstuFastest, 0.3s

sukantaLightest, 1.8 MB

steinumShortest, 654B

Submit

Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.