B. Monsters | Codeforces Solution | Educational Codeforces Round 152 (Rated for Div. 2)


Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are 𝑛 monsters, numbered from 1 to 𝑛 , and the 𝑖 -th of them has π‘Žπ‘– health points initially.

B. Monsters

time limit per test: 2 seconds | memory limit per test: 256 megabytes

Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are n monsters, numbered from 1 to n, and the i-th of them has ai health points initially.

Monocarp's character has an ability that deals k damage to the monster with the highest current health. If there are several of them, the one with the smaller index is chosen. If a monster's health becomes less than or equal to 0 after Monocarp uses his ability, then it dies.

Monocarp uses his ability until all monsters die. Your task is to determine the order in which monsters will die.

Input

The first line contains a single integer t (1 ≀ t ≀ 104) β€” the number of test cases.

The first line of each test case contains two integers n and k (1 ≀ n ≀ 3β‹…105; 1 ≀ k ≀ 109) β€” the number of monsters and the damage which Monocarp's ability deals.

The second line contains n integers a1, a2, …, an (1 ≀ ai ≀ 109) β€” the initial health points of monsters.

The sum of n over all test cases doesn’t exceed 3β‹…105.

Output

For each test case, print n integers β€” the indices of monsters in the order they die.

Example

Input

3
3 2
1 2 3
2 3
1 1
4 3
2 8 3 5

Output

2 1 3
1 2
3 1 2 4

Note

In the first example, the health points change as follows: [1, 2, 3] β†’ [1, 2, 1] β†’ [1, 0, 1] β†’ [βˆ’1, 0, 1] β†’ [βˆ’1, 0, βˆ’1]. The monster that is going to take damage the next time Monocarp uses his ability is underlined.

In the second example, the health points change as follows: [1, 1] β†’ [βˆ’2, 1] β†’ [βˆ’2, βˆ’2].

In the third example, the health points change as follows: [2, 8, 3, 5] β†’ [2, 5, 3, 5] β†’ [2, 2, 3, 5] β†’ [2, 2, 3, 2] β†’ [2, 2, 0, 2] β†’ [βˆ’1, 2, 0, 2] β†’ [βˆ’1, βˆ’1, 0, 2] β†’ [βˆ’1, βˆ’1, 0, βˆ’1].

struct Compare
{
    static bool cmp(const pii &a, const pii &b)
    {
        if (a.first == 0)
            return false;
        if (b.first == 0)
            return true;
        if (a.first == b.first)
            return a.second > b.second;
        return a.first < b.first;
    }

    bool operator()(const pii &a, const pii &b) const
    {
        return cmp(a, b);
    }
};

void solve()
{

    int n, k;
    cin >> n >> k;

    vi v(n);
    priority_queue<pair<int, int>, vector<pii>, Compare> q;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        int rem = v[i] % k;
        if (rem == 0)
            rem += k;
        q.push({rem, i});
    }

    while (!q.empty())
    {
        pii f = q.top();
        q.pop();
        cout << f.second + 1 << " ";
    }
    cout << endl;
}
TagsB. MonstersCodeforcesEducational Codeforces Round 152 (Rated for Div. 2)
Raunit Verma-picture
Raunit Verma

Technical Writer at CodingKaro

Share this on
CodingKaro Poster
CodingKaro
4.7

3K+ Downloads

One of its unique features is an automated coding contest reminder, which sets alarms for upcoming coding contests on popular platforms like CodeChef, CodeForces, and LeetCode, without the need for user input. This feature ensures that users never miss a coding contest and can stay updated with the latest coding challenges.

Download CodingKaro
Other Blogs in Codeforces