Universal Cup Judging System

Universal Cup

Time Limit: 6.0 s Memory Limit: 2048 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

Professor Chen, a distinguished expert in Computational Paleography, has spent years studying the scripts of the Non-Redundant dynasty. The scribes of this era followed a peculiar aesthetic doctrine: they believed that a text loses its spiritual potency if it contains "echoes".

In this context, an anagrammatic echo is defined as any two distinct segments of a text that, while not necessarily identical in their ordering, contain the exact same symbols in the exact same quantities. For a text represented as a sequence of symbols, an echo exists if there are two different starting positions $x$ and $y$ such that the subarray of length $l$ beginning at $x$ is a permutation of the subarray of length $l$ beginning at $y$. For example, consider the sequence $[1, 2, 1, 1, 3, 1, 2, 1]$. The segment of length $4$ starting at the second position, $[2, 1, 1, 3]$, and the segment of length $4$ starting at the fifth position, $[3, 1, 2, 1]$, form an anagrammatic echo.

Professor Chen has unearthed several such scrolls, but many symbols have faded over time, leaving gaps (represented by $0$). Your task is to fill these gaps using symbols from the allowed set $\{1, 2, \dots, k\}$ such that the resulting Dissonance Score of the scroll is minimized. The Dissonance Score is the maximum length $l$ of any anagrammatic echo present in the completed sequence.

Input

There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 10^4$) indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $k$ ($2 \le n \le 2 \times 10^5$, $1 \le k \le n$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le k$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \times 10^5$.

Output

For each test case, output $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le k$) representing the restored sequence. The sequence $b$ must match $a$ at all positions where $a_i \neq 0$, and it must achieve the minimum possible Dissonance Score.

If there are multiple ways to restore the scroll optimally, Professor Chen will accept any of them.

Example

Input

4
8 3
0 1 0 2 1 3 0 2
3 3
1 0 2
9 7
0 1 1 0 5 0 4 0 7
6 6
0 0 0 0 0 0

Output

1 1 3 2 1 3 2 2
1 3 2
2 1 1 3 5 6 4 4 7
1 2 3 4 5 6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.