Making some holes

It’s 3500 aG and our planet Earth is being represented by great athletes at the IOG (Intergalactic Olympic Games). The most exciting and hard-fought competition is the black plasmatic ball throwing. That competition takes place on an infinite flat base called RPC-314; on it, competitors throw away a really big ball made of a dense material called black plasma. All competitors are so strong that the ball will keep flying forever. This year the black plasma was extracted from the same supernova, so it will become unstable if all the balls get close at the same position (on the ground), because they will micro-explode generating a black hole by chain reaction, which would be really catastrophic. The game starts at some distance d of the x-axis. Each ball, say i, will always go to the right, bouncing for the first time at the coordinate (xi, 0). The i-plasma ball will bounce every xi − d units from the position where the game started. Also, because of the dragon equinox, all the balls will fly with the same x-velocity. The Olympic Commission sent some spacecraft to catch the balls before they meet each other, but the pilots need some help: they are really neither good at physics, nor at maths, so they don’t know where the balls will get together. Could you help them? Input The input consists of several test cases. The first line of each test case has an integer T (1 ≤ T ≤ 105), the number of test cases. The next line contains an integer n (2 ≤ n ≤ 10), the number of participants of the round, and an integer d (0 ≤ d ≤ 32768) the distance in the x-axis were the game starts. The third line has n integers, the integer xi is the distance from the origin of the Cartesian plane where the i-plasma ball will bounce the first time on the x-axis (d + 1 ≤ xi ≤ d + 100). Output For each test case print the distance from the starting point where all the balls will get together with an end of line. Sample Input 1 34 8 23 12 Sample Output 152