------
## 最终结论
```python
def k_amazing_numbers(t, test_cases):
    results = []
    for case in test_cases:
        n, a = case
        last_position = {}
        max_distance = [0] * (n + 1)

        for i in range(n):
            num = a[i]
            if num in last_position:
                distance = i - last_position[num]
                max_distance[num] = max(max_distance[num], distance)
            last_position[num] = i

        for num in last_position:
            distance = n - last_position[num]
            max_distance[num] = max(max_distance[num], distance)

        k_amazing = [-1] * n
        for num in range(1, n + 1):
            if max_distance[num] > 0:
                for k in range(max_distance[num]):
                    if k < n and (k_amazing[k] == -1 or num < k_amazing[k]):
                        k_amazing[k] = num
        
        results.append(k_amazing)

    return results

# Input reading and output formatting
import sys
input = sys.stdin.read
data = input().splitlines()

t = int(data[0])
test_cases = []
index = 1

for _ in range(t):
    n = int(data[index])
    a = list(map(int, data[index + 1].split()))
    test_cases.append((n, a))
    index += 2

results = k_amazing_numbers(t, test_cases)
for result in results:
    print(' '.join(map(str, result)))
```