You have to generate an array of N numbers.
The first element of the array is 0. You are given an additive factor k.
The ith element of the array is k plus the sum of all the elements till (i−1)th index (2≤i≤N).
You are given Q questions. In each question, you are given a number S.
You want to generate a number P closest to S such that P≤S . P is the sum of some array elements (an array element can be used atmost once).
For each question, you have to find the minimum difference between S and P.
Input format
The first line contains an integer T (the number of test cases).
The first line of each test case contains 3 space-separated integers N, k and Q.
Then Q lines follow and each line has an integer S.
Output format
For each test case, output Q space-separated integers, ith integer being the answer to ith question.
Answer for each test case should come in a new line.
Constraints
1≤T≤100
0≤N≤1000
1≤Q≤1000
1≤k,S≤109
For both the cases we have N=3 K=2 which means array is 0,2,4.
Questions in first case are 2 and 8.
2 can be paid using the 2nd array element. As he can pay entirely output is 0.
8 cannot be completely paid.He can pay 6 at max so the amount which he can't pay is 2 (8-6) .
Question in second case are 5 and 1.
5 cannot be completely paid.He can use third array element to pay 4.So amount which can't be paid is 1.