Submit Best Submissions All Submissions

181. Rami and Children


Problem Statement:
There are n children in Rami's school. Rami is going to give some candies to them. Let us number all the children from 1 to n. The i-th child wants to get at least ai candies.

Rami asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Rami start distribution of the candies. He follows the algorithm:

- Give m candies to the first child of the line.
- If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Rami wants to know, which child will be the last in this order?


Input Format:
The first line of input has one integer T, which is the number of test cases. T test cases follow

The first line of each test case contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100).

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).


Output Format:
For each test case, output a single integer, representing the number of the last child.


Sample Input:
2 5 2 1 3 1 4 2 6 4 1 1 2 2 3 3


Sample Output:
4 6


Notes:
In the first test case: Firstly, child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.

Child 4 is the last one who goes home.





Added by: samiemad
Added at: 2014-07-26 09:00:13 UTC
Time Limit: 1 second
Partial score: No
Source:Practical C++ and Algorithms Course, Level 1, By. Sami EMAD