You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.

Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.

For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the elements of the array.

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


-----Output-----

For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.


-----Examples-----

Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1 
-1 4 4 4 2 
-1 -1 1 1 1 1


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM
Tags: Sorting

Amortized analysis

Data structures

Implementation


Solutions:
from math import inf
for _ in range(int(input())):
	n = int(input())
	a = [int(X) for X in input().split()]
	x = [0 for i in range(n + 1)]
	vis = [0 for i in range(n + 1)]
	for i in range(n):
		x[a[i]] = max(x[a[i]], i + 1 - vis[a[i]])
		vis[a[i]] = i + 1
	for i in range(n):
		x[a[i]] = max(x[a[i]], n + 1 - vis[a[i]])
	an = [inf for i in range(n + 1)]
	for i in range(1, n + 1):
		an[x[i]] = min(i, an[x[i]])
	p = -1
	for i in range(1, n + 1):
		if an[i] != inf and p == -1:
			p = 10 ** 6
		else:
			an[i] = min(p, an[i - 1], an[i])
	print(*an[1:])


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		d = defaultdict(list)
		for x in range(n):
			d[l[x]].append(x)
		ans = [-1] * n
		for x in d:
			temp = [-1] + d[x] + [n]
			mi = 0
			for y in range(len(temp) - 1):
				mi = max(mi, temp[y + 1] - temp[y])
			if mi != 0:
				if ans[mi - 1] != -1:
					if ans[mi - 1] > x:
						ans[mi - 1] = x
				else:
					ans[mi - 1] = x
		temp = -1
		for x in range(n):
			if ans[x] == -1:
				ans[x] = temp
			else:
				if temp == -1:
					temp = ans[x]
				else:
					temp = min(ans[x], temp)
				ans[x] = temp
		print(*ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	v = dict()
	for i in range(n):
		d[a[i]] = (-1, 0)
		v[i + 1] = n + 1
	for i in range(n):
		(last, p) = d[a[i]]
		p_new = i - last
		p = max(p_new, p)
		d[a[i]] = (i, p)
	ans = n + 1
	for k in d.keys():
		(last, p) = d[k]
		p_new = n - last
		p = max(p_new, p)
		v[p] = min(v[p], k)
		if p <= ans:
			ans = p
			v[p] = min(k, v[p])
	last = n + 1
	for k in range(1, n + 1):
		if k < ans:
			print(-1, end=' ')
		else:
			last = min(v[k], last)
			print(last, end=' ')
	print()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	bef = [-1 for _ in range(n)]
	max_d = [-1 for _ in range(n)]
	for (i, a) in enumerate(alst):
		max_d[a - 1] = max(max_d[a - 1], i - bef[a - 1])
		bef[a - 1] = i
	for i in range(n):
		max_d[i] = max(max_d[i], n - bef[i])
	ans = [-1 for _ in range(n)]
	for (i, num) in enumerate(max_d):
		for j in range(num - 1, n):
			if ans[j] != -1:
				break
			ans[j] = i + 1
	print(*ans)
for _ in range(int(input())):
	main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	last = [-1] * (n + 1)
	best = [1] * (n + 1)
	for i in range(n):
		v = l[i]
		diff = i - last[v]
		best[v] = max(best[v], diff)
		last[v] = i
	for v in range(n + 1):
		diff = n - last[v]
		best[v] = max(best[v], diff)
	rev = [n + 1] * (n + 2)
	for i in range(n, -1, -1):
		rev[best[i]] = i
	soFar = n + 1
	out = []
	for i in range(1, n + 1):
		soFar = min(soFar, rev[i])
		if soFar > n:
			out.append(-1)
		else:
			out.append(soFar)
	print(' '.join(map(str, out)))


import math
a = int(input())
for i in range(a):
	n = input()
	z = list(map(int, input().split()))
	from collections import *
	al = defaultdict(list)
	dl = [math.inf for i in range(len(z) + 5)]
	for i in range(len(z)):
		al[z[i]].append(i + 1)
	for i in al:
		t = al[i]
		gap = 0
		gap = max(gap, t[0])
		for x in range(1, len(t)):
			gap = max(gap, t[x] - t[x - 1])
		gap = max(len(z) - t[-1] + 1, gap)
		dl[gap] = min(dl[gap], i)
	ans = []
	for i in range(len(z)):
		if i == 0:
			if dl[1] == math.inf:
				ans.append(-1)
			else:
				ans.append(dl[1])
		else:
			dl[i + 1] = min(dl[i], dl[i + 1])
			if dl[i + 1] == math.inf:
				ans.append(-1)
			else:
				ans.append(dl[i + 1])
	print(*ans)


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()

def pr(*args, end='\n'):
	for _arg in args:
		sys.stdout.write(str(_arg) + ' ')
	sys.stdout.write(end)
inf = float('inf')
enum = enumerate
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	a = inar()
	last = [-1 for i in range(n + 1)]
	gap = [-1 for i in range(n + 1)]
	for i in range(n):
		gap[a[i]] = max(gap[a[i]], i - last[a[i]])
		last[a[i]] = i
	for i in a:
		gap[i] = max(gap[i], n - last[i])
	gapmin = [inf for i in range(n + 1)]
	for i in range(1, n + 1):
		if gap[i] == -1:
			continue
		gapmin[gap[i]] = min(gapmin[gap[i]], i)
	for i in range(1, n + 1):
		gapmin[i] = min(gapmin[i - 1], gapmin[i])
	for i in range(n + 1):
		if gapmin[i] == inf:
			gapmin[i] = -1
	pr(*gapmin[1:])


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
inf = 10 ** 9
for _ in range(II()):
	n = II()
	aa = LI()
	mx = n + 5
	ww = [-1] * mx
	pos = [-1] * mx
	for (i, a) in enumerate(aa):
		ww[a] = max(ww[a], i - pos[a])
		pos[a] = i
	for a in range(mx):
		if pos[a] == -1:
			continue
		ww[a] = max(ww[a], n - pos[a])
	ktoa = [inf] * (n + 1)
	for a in range(mx):
		if ww[a] == -1:
			continue
		ktoa[ww[a]] = min(ktoa[ww[a]], a)
	mn = inf
	ans = []
	for k in range(1, n + 1):
		mn = min(mn, ktoa[k])
		if mn == inf:
			ans.append(-1)
		else:
			ans.append(mn)
	print(*ans)


from collections import defaultdict

def f(i):
	md = i[1] + 1
	for j in range(2, len(i)):
		md = max(md, i[j] - i[j - 1])
	return md
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		if len(d[a[i]]) == 0:
			d[a[i]].append(-1)
		d[a[i]].append(i)
	for i in d:
		d[i].append(n)
	ans = [-1] * (n + 1)
	x = sorted(list(d.keys()))
	for j in x:
		md = f(d[j])
		for i in range(md, n + 1):
			if ans[i] != -1:
				break
			ans[i] = j
	print(*ans[1:])


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 10 ** 9 + 7
for _ in range(int(data())):
	n = int(data())
	a = mdata()
	d = dd(int)
	d1 = dd(int)
	for i in range(n):
		d1[a[i]] = max(d1[a[i]], i - d[a[i]] + 1)
		d[a[i]] = i + 1
	ans = [INF] * n
	for i in d1:
		d1[i] = max(d1[i], n + 1 - d[i])
		ans[d1[i] - 1] = min(ans[d1[i] - 1], i)
	m = INF
	for i in range(n):
		m = min(m, ans[i])
		ans[i] = m
		if ans[i] == INF:
			ans[i] = -1
	outl(ans)


def func(n, a):
	c = [-1] * (n + 1)
	f = [0] * (n + 1)
	indices = [[] for _ in range(n + 1)]
	for i in range(n):
		indices[a[i]].append(i + 1)
	for i in range(1, n + 1):
		lis = indices[i]
		if lis != []:
			m = max(lis[0], n - lis[-1] + 1)
			for j in range(1, len(lis)):
				m = max(m, lis[j] - lis[j - 1])
			f[i] = m
	for i in range(1, n + 1):
		m = f[i]
		if m != 0:
			while m < n + 1 and c[m] == -1:
				c[m] = i
				m += 1
	return c[1:]
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = func(n, arr)
	print(' '.join(list(map(str, brr))))


from collections import defaultdict
t = int(input())
for _ in range(t):
	Dict = defaultdict(list)
	n = int(input())
	arr = [int(i) for i in input().split()]
	for i in range(n):
		Dict[arr[i]].append(i)
	ans = [n * n] * (n + 1)
	for i in list(Dict.keys()):
		prev = -1
		mx = 0
		for j in Dict[i]:
			temp = j - prev
			mx = max(mx, temp)
			prev = j
		mx = max(mx, n - prev)
		ans[mx] = min(ans[mx], i)
	for i in range(1, n + 1):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(1, n + 1):
		if ans[i] == n * n:
			ans[i] = -1
	print(*ans[1:n + 1])


class PosIndexer:

	def __init__(self, nums):
		self.build(nums)

	def build(self, nums):
		self.pos_of_nums = [[] for i in range(len(nums) + 1)]
		for num in range(1, len(nums) + 1):
			self.pos_of_nums[num].append(0)
		for (index, num) in enumerate(nums):
			self.pos_of_nums[num].append(index + 1)
		for num in range(1, len(nums) + 1):
			self.pos_of_nums[num].append(len(nums) + 1)

	def find_max_range_for_num(self, num):
		return max([self.pos_of_nums[num][pos_index] - self.pos_of_nums[num][pos_index - 1] for pos_index in range(1, len(self.pos_of_nums[num]))])

def solve(nums):
	results = [-1 for i in range(len(nums) + 1)]
	pos_indexer = PosIndexer(nums)
	for num in range(1, len(nums) + 1):
		max_range_for_num = pos_indexer.find_max_range_for_num(num)
		if max_range_for_num <= len(nums) and results[max_range_for_num] == -1:
			results[max_range_for_num] = num
	for num in range(1, len(nums) + 1):
		if results[num - 1] != -1:
			if results[num] == -1:
				results[num] = results[num - 1]
			else:
				results[num] = min(results[num], results[num - 1])
	return results[1:]
for _ in range(int(input())):
	_ = int(input())
	nums = [int(token) for token in input().split()]
	result = solve(nums)
	print(*result)


import sys

def input():
	return sys.stdin.readline()
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	X = [0] * n
	Y = [-1] * n
	for i in range(n):
		a = A[i]
		Y[a - 1] = max(Y[a - 1], i - X[a - 1])
		X[a - 1] = i + 1
	ans = [-1] * n
	for i in range(n):
		if X[i]:
			Y[i] = max(Y[i], n - X[i])
			if ans[Y[i]] == -1:
				ans[Y[i]] = i + 1
	for i in range(1, n):
		if ans[i - 1] != -1:
			if ans[i] == -1:
				ans[i] = ans[i - 1]
			else:
				ans[i] = min(ans[i], ans[i - 1])
	print(*ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = [-1] * n
		b = [[] for _ in range(n + 1)]
		for (i, v) in enumerate(a):
			b[v].append(i)
		c = []
		for i in range(1, n + 1):
			if b[i]:
				ma = b[i][0] + 1
				for j in range(len(b[i]) - 1):
					ma = max(ma, b[i][j + 1] - b[i][j])
				ma = max(ma, n - b[i][-1])
				c.append((i, ma))
		c.sort()
		for i in c:
			for j in range(i[1] - 1, n):
				if ans[j] != -1:
					break
				ans[j] = i[0]
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import collections

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(_, a) = (inp(), inlt())
	res = [-1] * len(a)
	idxs = collections.defaultdict(list)
	max_int = {}
	last_i = {}
	for (i, num) in enumerate(a):
		if num not in max_int:
			max_int[num] = i + 1
			last_i[num] = i
		else:
			max_int[num] = max(i - last_i[num], max_int[num])
			last_i[num] = i
	for num in max_int:
		max_int[num] = max(max_int[num], len(a) - last_i[num])
	ints = sorted(max_int.keys(), key=lambda a: (max_int[a], a))
	best = ints[0]
	inti = 0
	for i in range(max_int[ints[0]], len(res) + 1):
		while inti < len(ints) and i == max_int[ints[inti]]:
			best = min(ints[inti], best)
			inti += 1
		res[i - 1] = best
	print(' '.join([str(x) for x in res]))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(list)
	l = []
	for i in range(n):
		d[arr[i]].append(i)
	for i in d:
		ma = d[i][0] + 1
		c = d[i][0]
		for j in d[i][1:]:
			ma = max(ma, j - c)
			c = j
		ma = max(ma, n - d[i][-1])
		l.append([ma, i])
	l.append([n + 1, 100000000000])
	ans = [-1] * n
	l.sort(key=lambda x: (x[0], -x[1]))
	mi = 10000000000000
	for i in range(len(l) - 1):
		if l[i + 1][0] == l[i][0]:
			continue
		mi = min(mi, l[i][1])
		for j in range(l[i][0], l[i + 1][0]):
			ans[j - 1] = mi
	print(*ans)


import sys
from sys import stdin, stdout
ipi = lambda : int(stdin.readline())
ipil = lambda : map(int, stdin.readline().split())
ipf = lambda : float(stdin.readline())
ipfl = lambda : map(float, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
outl = lambda x: print(*x)
T = ipi()
for _ in range(T):
	n = ipi()
	a = list(ipil())
	last_occur = dict()
	dis = dict()
	for i in range(n):
		tmp = a[i]
		lst_pos = last_occur.get(tmp)
		if lst_pos is None:
			last_occur[tmp] = i
			dis[tmp] = i + 1
		else:
			last_occur[tmp] = i
			dis[tmp] = max(dis[tmp], i - lst_pos)
	for (k, v) in last_occur.items():
		dis[k] = max(dis[k], n - v)
	ans = [-1] * n
	for (k, v) in dis.items():
		if ans[v - 1] == -1:
			ans[v - 1] = k
		else:
			ans[v - 1] = min(ans[v - 1], k)
	flag = -1
	for i in range(n):
		if ans[i] != -1:
			if flag != -1:
				ans[i] = min(flag, ans[i])
			flag = ans[i]
		else:
			ans[i] = flag
	outl(ans)


import io
import os
from collections import Counter, defaultdict, deque
inf = float('inf')

def solve(N, A):
	valToIndices = defaultdict(list)
	for (i, x) in enumerate(A):
		valToIndices[x].append(i)
	valToGap = {}
	for (x, indices) in valToIndices.items():
		maxGap = max(indices[0] + 1, N - indices[-1])
		for (i, j) in zip(indices, indices[1:]):
			maxGap = max(maxGap, j - i)
		valToGap[x] = maxGap
	best = [inf] * (N + 1)
	for (k, v) in valToGap.items():
		best[v] = min(best[v], k)
	for (k, b) in enumerate(best):
		if k >= 1:
			best[k] = min(best[k - 1], b)
	ans = [-1 if x == inf else x for x in best][1:]
	return ' '.join(map(str, ans))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
INF = 10 ** 9 + 7
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	table = [-1] * (N + 1)
	pre = [-1] * (N + 1)
	for i in range(N):
		a = A[i]
		table[a] = max(table[a], i - pre[a])
		pre[a] = i
	for a in range(1, N + 1):
		table[a] = max(table[a], N - pre[a])
	leng = [INF] * (N + 1)
	for a in range(N, 0, -1):
		if table[a] == N + 1:
			continue
		leng[table[a]] = a
	for i in range(2, N + 1):
		leng[i] = min(leng[i], leng[i - 1])
	for i in range(1, N + 1):
		if leng[i] == INF:
			leng[i] = -1
	Ans[qu] = ' '.join(map(str, leng[1:]))
print('\n'.join(Ans))


import sys
input = iter(sys.stdin.read().splitlines()).__next__
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	occurrences = [[-1] for _ in range(n + 1)]
	for (i, a_i) in enumerate(a):
		occurrences[a_i].append(i)
	subsegment_lengths = []
	for (val, occ) in enumerate(occurrences):
		if len(occ) == 1:
			continue
		occ.append(n)
		min_k = max((occ[i + 1] - occ[i] for i in range(len(occ) - 1)))
		subsegment_lengths.append((val, min_k))
	k_amazing = [n + 1] * n
	for (num, k) in subsegment_lengths:
		k_amazing[k - 1] = min(num, k_amazing[k - 1])
	for i in range(1, n):
		k_amazing[i] = min(k_amazing[i], k_amazing[i - 1])
	for (i, num) in enumerate(k_amazing):
		if num > n:
			k_amazing[i] = -1
	print(*k_amazing)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	numberLocations = [[-1] for __ in range(n + 1)]
	ans = [-1 for __ in range(n + 1)]
	for i in range(n):
		numberLocations[a[i]].append(i)
	for i in range(n + 1):
		numberLocations[i].append(n)
	for no in range(n, 0, -1):
		maxGap = -float('inf')
		temp = numberLocations[no]
		for j in range(1, len(temp)):
			maxGap = max(maxGap, temp[j] - temp[j - 1])
		if maxGap < n + 1:
			ans[maxGap] = no
	minSoFar = n + 1
	for i in range(n + 1):
		if ans[i] != -1:
			minSoFar = min(minSoFar, ans[i])
			ans[i] = min(ans[i], minSoFar)
		elif minSoFar != n + 1:
			ans[i] = minSoFar
	print(' '.join([str(x) for x in ans[1:]]))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : [0, -1])
	fin = [-1 for i in range(n)]
	for (j, i) in enumerate(l):
		curr = j - d[i][1] - 1
		d[i] = [max(d[i][0], curr), j]
	for (i, j) in sorted(d.items()):
		val = max(j[0], n - 1 - j[1])
		fin[val] = i if fin[val] == -1 else fin[val]
	chk = False
	for i in range(n):
		if chk:
			fin[i] = min(fin[i], fin[i - 1]) if fin[i] != -1 else fin[i - 1]
		if chk == False and fin[i] != -1:
			chk = True
	print(*fin)


from collections import *
import sys
input = sys.stdin.readline

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	n = ri()
	aa = rl()
	dd = defaultdict(list)
	for (i, ai) in enumerate(aa):
		dd[ai].append(i + 1)
	for key in dd.keys():
		dd[key].append(0)
		dd[key].append(n + 1)
	gaps = defaultdict(int)
	for key in dd.keys():
		dd[key].sort()
		gaps[key] = max([dd[key][i] - dd[key][i - 1] - 1 for i in range(1, len(dd[key]))])
	ans = [10 ** 18] * n
	for key in gaps.keys():
		ans[gaps[key]] = min(ans[gaps[key]], key)
	for i in range(1, n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		if ans[i] == 10 ** 18:
			ans[i] = -1
	print(' '.join([str(x) for x in ans]))


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	lis = [0] * (n + 1)
	md = [float('-inf')] * (n + 1)
	for i in range(n):
		md[a[i]] = max(md[a[i]], i + 1 - lis[a[i]])
		lis[a[i]] = i + 1
	for i in range(n + 1):
		md[i] = max(md[i], n + 1 - lis[i])
	itr = n - 1
	ans = [-1] * n
	for i in range(1, n + 1):
		while md[i] <= itr + 1:
			ans[itr] = i
			itr -= 1
	print(*ans)


import sys, math, cmath, time, collections
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	q = dict()
	qq = [-1] * len(a)
	for i in range(len(a)):
		if a[i] in q:
			q[a[i]].append(i)
		else:
			q[a[i]] = [-1, i]
	q = collections.OrderedDict(sorted(q.items()))
	for i in q:
		q[i].append(len(a))
		w = 0
		for j in range(1, len(q[i])):
			w = max(w, q[i][j] - q[i][j - 1])
		qw = w - 1
		if qq[qw] == -1:
			qq[qw] = i
	ww = -1
	for i in range(len(qq)):
		if qq[i] != -1:
			if ww == -1:
				ww = qq[i]
			qq[i] = min(ww, qq[i])
			ww = qq[i]
		else:
			qq[i] = ww
	sys.stdout.write(' '.join(map(str, qq)) + '\n')

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	import io, os
	input = sys.stdin.readline
main()


import typing
import sys
import math
import collections
import bisect
import itertools
import fractions
import copy
import heapq
import decimal
import queue
INF = 10 ** 20
MOD = 998244353

def ni():
	return int(sys.stdin.readline())

def ns():
	return map(int, sys.stdin.readline().split())

def na():
	return list(map(int, sys.stdin.readline().split()))

def main():
	t = ni()
	for _ in range(t):
		n = ni()
		a = na()
		res = [-1 for _ in range(n)]
		latest = [-1 for _ in range(n)]
		for (i, ai) in enumerate(a):
			tai = ai - 1
			tmp = i - latest[tai]
			res[tai] = max(res[tai], tmp)
			latest[tai] = i
		for i in range(n):
			if res[i] == -1:
				continue
			res[i] = max(res[i], n - latest[i])
		ans = [INF for _ in range(n)]
		for i in range(n):
			if res[i] == -1:
				continue
			ans[res[i] - 1] = min(ans[res[i] - 1], i + 1)
		for i in range(1, n):
			if ans[i] > ans[i - 1]:
				ans[i] = ans[i - 1]
		for i in range(n):
			if ans[i] == INF:
				ans[i] = -1
		print(*ans, sep=' ')
main()


T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(x) - 1 for x in input().split()]
	prev = [-1 for _ in range(n)]
	val = [1 for _ in range(n)]
	for (i, x) in enumerate(a):
		delta = i - prev[x]
		val[x] = max(val[x], delta)
		prev[x] = i
	for i in range(n):
		val[i] = max(val[i], n - prev[i])
	ans = [-1 for _ in range(n + 1)]
	r = n + 1
	for i in range(n):
		if val[i] < r:
			for j in range(val[i], r):
				ans[j] = i + 1
			r = val[i]
	print(' '.join([str(x) for x in ans[1:]]))


def solve():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	last_occur = [-1 for i in range(n + 1)]
	max_dist = [0 for i in range(n + 1)]
	max_dist[0] = n
	for i in range(n):
		elem = a[i]
		dist = i - last_occur[elem] - 1
		max_dist[elem] = max(dist, max_dist[elem])
		last_occur[elem] = i
	for i in range(n):
		elem = i + 1
		dist = n - last_occur[elem] - 1
		max_dist[elem] = max(dist, max_dist[elem])
	max_dist = [(max_dist[i], i) for i in range(1, n + 1)]
	max_dist.sort()
	cursor = 0
	min_so_far = n + 1
	for k in range(1, n + 1):
		while cursor < n and max_dist[cursor][0] < k:
			min_so_far = min(max_dist[cursor][1], min_so_far)
			cursor += 1
		if min_so_far == n + 1:
			print(-1, end=' ')
		else:
			print(min_so_far, end=' ')
	print()
t = int(input().strip())
for _ in range(t):
	solve()


import math
a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	from collections import *
	al = defaultdict(list)
	for i in range(len(z)):
		if len(al[z[i]]) == 0:
			al[z[i]].append(0)
			al[z[i]].append(i + 1)
		else:
			al[z[i]].append(i + 1)
	for i in al:
		al[i].append(len(z) + 1)
	t1 = 0
	save = -1
	mini = math.inf
	ans = defaultdict(int)
	for i in al:
		t1 = 0
		for t in range(1, len(al[i])):
			t1 = max(al[i][t] - al[i][t - 1], t1)
		if ans[t1] == 0:
			ans[t1] = i
		else:
			ans[t1] = min(ans[t1], i)
	fin = []
	flag = 0
	for i in range(len(z)):
		if ans[i + 1] == 0 and flag == 0:
			fin.append(-1)
			continue
		if ans[i + 1] != 0 and flag == 0:
			fin.append(ans[i + 1])
			flag = 1
			continue
		elif ans[i + 1] == 0:
			ans[i + 1] = fin[-1]
			fin.append(fin[-1])
			continue
		else:
			ans[i + 1] = min(fin[-1], ans[i + 1])
			fin.append(ans[i + 1])
			continue
	print(*fin)


import sys
import math
input = sys.stdin.readline

def algo(arr, n):
	ans = [-1] * (n + 1)
	f = [0] * (n + 1)
	idx = [0] * (n + 1)
	for i in range(1, n + 1):
		f[arr[i - 1]] = max(i - idx[arr[i - 1]], f[arr[i - 1]])
		idx[arr[i - 1]] = i
	for i in range(1, n + 1):
		f[arr[i - 1]] = max(n + 1 - idx[arr[i - 1]], f[arr[i - 1]])
	for i in range(1, n + 1):
		if ans[f[i]] == -1:
			ans[f[i]] = i
	ans[0] = -1
	for i in range(1, n + 1):
		if ans[i] == -1:
			ans[i] = ans[i - 1]
		else:
			ans[i] = ans[i] if ans[i - 1] == -1 else min(ans[i], ans[i - 1])
	return ' '.join(map(str, ans[1:]))
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = algo(arr, n)
	print(res)


import math
T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	d = False
	m = [0] * (n + 1)
	lm = [-1] * (n + 1)
	app = set(a)
	for i in range(n):
		m[a[i]] = max(m[a[i]], i - lm[a[i]])
		lm[a[i]] = i
	for i in app:
		if m[i] != 0:
			m[i] = max(m[i], n - lm[i])
	ans = [-1] * n
	for i in app:
		if ans[m[i] - 1] != -1:
			ans[m[i] - 1] = min(ans[m[i] - 1], i)
		else:
			ans[m[i] - 1] = i
	nn = 1
	mmm = n + 1
	for i in range(n):
		if ans[i] != -1:
			nn = 0
		if nn:
			ans[i] = '-1'
		else:
			if ans[i] != -1:
				mmm = min(mmm, ans[i])
			ans[i] = str(mmm)
	print(' '.join(ans))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ls = [[] for i in range(n + 5)]
	for i in range(n):
		ls[a[i]].append(i)
	ans = [-1] * n
	mx = n
	for i in range(1, n + 1):
		n1 = len(ls[i])
		if n1 > 0:
			cnt = ls[i][0]
			for j in range(1, n1):
				cnt = max(cnt, ls[i][j] - 1 - ls[i][j - 1])
			cnt = max(cnt, n - ls[i][-1] - 1)
			for j in range(cnt, mx):
				ans[j] = i
			mx = min(mx, cnt)
	for i in ans:
		print(i, end=' ')
	print()


import math
import os
from io import BytesIO, IOBase
import sys
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	last_seen = defaultdict(int)
	max_dist = {}
	for (idx, val) in enumerate(a):
		if val in max_dist:
			max_dist[val] = max(max_dist[val], idx - last_seen[val])
		else:
			max_dist[val] = idx + 1
		last_seen[val] = idx
	for (val, idx) in last_seen.items():
		max_dist[val] = max(max_dist[val], n - idx)
	results = {}
	for (val, md) in max_dist.items():
		if md in results:
			results[md] = min(val, results[md])
		else:
			results[md] = val
	output = []
	best = -1
	for i in range(1, n + 1):
		if i in results:
			if best == -1:
				best = results[i]
			else:
				best = min(results[i], best)
		output.append(best)
	print(' '.join([str(x) for x in output]))


import sys

def inp():
	return sys.stdin.readline()
for _ in range(int(inp())):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	last = [-1 for i in range(n + 1)]
	gap = [0 for i in range(n + 1)]
	for i in range(n):
		gap[a[i]] = max(gap[a[i]], i - last[a[i]])
		last[a[i]] = i
	for v in range(1, n + 1):
		gap[v] = max(gap[v], n - last[v])
	INF = 10 ** 9
	candidates = [INF for i in range(n + 2)]
	for v in range(1, n + 1):
		candidates[gap[v]] = min(candidates[gap[v]], v)
	ans = INF
	for k in range(1, n + 1):
		ans = min(ans, candidates[k])
		print(-1 if ans == INF else ans, end=' ')
	print()


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	p = dict()
	b = dict()
	i = 0
	n = mint()
	for x in mints():
		if x in p:
			b[x] = max(b[x], i - p[x])
		else:
			b[x] = i + 1
		p[x] = i
		i += 1
	res = []
	for (x, y) in b.items():
		res.append((max(b[x], n - p[x]), x))
	res.sort()
	j = 0
	cur = int(1000000000.0)
	rr = [-1] * n
	for i in range(1, n + 1):
		while j < len(res) and res[j][0] <= i:
			cur = min(cur, res[j][1])
			j += 1
		if cur <= n:
			rr[i - 1] = cur
	print(' '.join(map(str, rr)))
for i in range(mint()):
	solve()


import sys
input = sys.stdin.readline
INF = 10 ** 18
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	tmp = [[-1] for _ in range(n + 1)]
	for i in range(n):
		tmp[arr[i]].append(i)
	mins = [INF] * (n + 1)
	for i in range(1, n + 1):
		if tmp[i][-1] == -1:
			continue
		cnt = 0
		prev = tmp[i][0]
		for val in tmp[i][1:]:
			cnt = max(cnt, val - prev)
			prev = val
		cnt = max(cnt, n - prev)
		mins[cnt] = min(mins[cnt], i)
	tmin = INF
	for i in range(1, n + 1):
		tmin = min(tmin, mins[i])
		if tmin == INF:
			mins[i] = -1
		else:
			mins[i] = tmin
	print(*mins[1:])


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	g = [[-1] for _ in range(n + 1)]
	for i in range(n):
		g[s[i]].append(i)
	inf = 10 ** 10
	ans = [-1] * n
	lstunused = n
	for i in range(1, n + 1):
		g[i].append(n)
		mx = 0
		for j in range(1, len(g[i])):
			mx = max(mx, g[i][j] - g[i][j - 1] - 1)
		for j in range(mx, lstunused):
			ans[j] = i
		lstunused = min(lstunused, mx)
	print(*ans)


from collections import defaultdict

def max_gap(ids):
	L = len(ids)
	g = 0
	for i in range(1, L):
		g = max(ids[i] - ids[i - 1], g)
	return g

def solve(n, a):
	v2i = defaultdict(lambda : [0])
	for i in range(n):
		v2i[a[i]].append(i + 1)
	for v in v2i:
		v2i[v].append(n + 1)
	g2v = dict()
	for v in v2i:
		g = max_gap(v2i[v])
		if g not in g2v:
			g2v[g] = v
		else:
			g2v[g] = min(g2v[g], v)
	min_v = -1
	ans = []
	for k in range(1, n + 1):
		if k in g2v:
			if min_v == -1:
				ans.append(g2v[k])
				min_v = g2v[k]
			else:
				min_v = min(min_v, g2v[k])
				ans.append(min_v)
		else:
			ans.append(min_v)
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = solve(n, a)
	print(*ans, sep=' ')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ind = [[] for i in range(n)]
		for i in range(n):
			ind[a[i] - 1].append(i)
		freq = [int(100000000.0)] * n
		for i in range(n):
			if ind[i] == []:
				continue
			mx = 0
			start = -1
			for j in range(len(ind[i])):
				mx = max(mx, ind[i][j] - start)
				start = ind[i][j]
			mx = max(mx, n - start)
			freq[mx - 1] = min(freq[mx - 1], i + 1)
		for i in range(n):
			if freq[i] < int(100000000.0):
				start = i
				break
			freq[i] = -1
		m = 100000000.0
		for i in range(start, n):
			m = min(m, freq[i])
			freq[i] = m
		print(*freq)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
from collections import deque
import bisect
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
T = int(input())
for _ in range(T):
	n = int(R())
	l = RL(int)
	ind = [0] * (n + 1)
	max_diff = [0] * (n + 1)
	max_diff[0] = 10 ** 5
	for i in range(1, n + 1):
		max_diff[l[i - 1]] = max(max_diff[l[i - 1]], i - ind[l[i - 1]])
		ind[l[i - 1]] = i
	for i in range(1, n + 1):
		max_diff[l[i - 1]] = max(max_diff[l[i - 1]], n + 1 - ind[l[i - 1]])
	ans = [-1] * n
	for i in range(n):
		if max_diff[i + 1] != 0:
			if ans[max_diff[i + 1] - 1] == -1:
				ans[max_diff[i + 1] - 1] = i + 1
	ini = -1
	for i in range(n):
		if ans[i] == -1:
			ans[i] = ini
		elif ans[i] != ini:
			ini = ans[i]
	for i in range(n):
		if ans[i] != -1:
			mi = ans[i]
			break
	for i in range(1, n):
		if ans[i] != -1:
			if ans[i] > mi:
				ans[i] = mi
			else:
				mi = ans[i]
	print(*ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	p = [-1 for _ in range(n)]
	f = [0 for _ in range(n)]
	for i in range(n):
		element = a[i] - 1
		f[element] = max(f[element], i - p[element])
		p[element] = i
	ans = [-1 for _ in range(n + 1)]
	for x in range(n):
		f[x] = max(f[x], n - p[x])
		i = f[x]
		while i <= n and ans[i] == -1:
			ans[i] = x + 1
			i += 1
	for c in ans[1:]:
		print(c, end=' ')
	print('')
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if lis[i] not in d:
			d[lis[i]] = []
			d[lis[i]].append(i)
		else:
			d[lis[i]].append(i)
	for i in d:
		d[i].append(n)
	ans = [1000000000000] * n
	for i in d:
		pre = -1
		mx = 0
		for j in d[i]:
			mx = max(mx, j - pre)
			pre = j
		if ans[mx - 1] == -1:
			ans[mx - 1] = i
		else:
			ans[mx - 1] = min(ans[mx - 1], i)
	prev = 1000000000000
	for i in range(n):
		ans[i] = min(ans[i], prev)
		prev = min(ans[i], prev)
	for i in range(n):
		if ans[i] == 1000000000000:
			ans[i] = -1
	print(*ans)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	dist = {}
	last = {}
	for i in range(n):
		x = a[i]
		if dist.get(x, -1) == -1:
			dist[x] = i + 1
			last[x] = i
		else:
			dist[x] = max(dist[x], i - last[x])
			last[x] = i
	for ele in dist:
		dist[ele] = max(dist[ele], n - last[ele])
	ulta = {}
	for ele in dist:
		ulta[dist[ele]] = min(ele, ulta.get(dist[ele], 2 * n))
	li = [2 * n] * (n + 1)
	for ele in ulta:
		li[ele] = ulta[ele]
	for i in range(1, n + 1):
		li[i] = min(li[i - 1], li[i])
	for i in range(1, n + 1):
		if li[i] == 2 * n:
			print(-1, end=' ')
		else:
			print(li[i], end=' ')
	print()
	return
t = II()
for i in range(t):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	l = [-1] * n
	u = [-1] * n
	k = [-1] * n
	for x in range(n):
		i = a[x] - 1
		l[i] = max(l[i], x - u[i])
		u[i] = x
	m = n
	i = [x for x in range(n) if l[x] != -1]
	for x in i:
		a = max(l[x], n - u[x])
		if l[x] <= m and k[a - 1] == -1:
			for j in range(a - 1, m):
				k[j] = x + 1
			m = a - 1
	print(*k)


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	pre = {}
	l = [0] * n
	for j in range(n - 1, -1, -1):
		l[j] = pre.get(a[j], n) - j
		pre[a[j]] = j
	pre = {}
	d = {}
	l2 = [0] * n
	for j in range(n):
		l2[j] = j - pre.get(a[j], -1)
		pre[a[j]] = j
		d[a[j]] = 0
	for j in range(n):
		d[a[j]] = max(d[a[j]], l[j], l2[j])
	l = [10 ** 6] * n
	for j in d:
		l[d[j] - 1] = min(l[d[j] - 1], j)
	if l[0] == 10 ** 6:
		print(-1, end=' ')
	else:
		print(l[0], end=' ')
	for j in range(1, n):
		l[j] = min(l[j], l[j - 1])
		if l[j] == 10 ** 6:
			print(-1, end=' ')
		else:
			print(l[j], end=' ')
	print()


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, lst):
	cnt = {}
	for i in range(len(lst)):
		if cnt.get(lst[i]) == None:
			cnt[lst[i]] = [i + 1, i]
		else:
			cnt[lst[i]] = [max(cnt[lst[i]][0], i - cnt[lst[i]][1]), i]
	for i in cnt:
		cnt[i] = [max(cnt[i][0], n - cnt[i][1]), cnt[i][1]]
	cnt = sortDictV(cnt)
	ans = [float('inf')] * (n + 1)
	for i in cnt:
		ans[cnt[i][0]] = min(ans[cnt[i][0] - 1], ans[cnt[i][0]], i)
	prev = float('inf')
	for i in ans[1:]:
		if min(i, prev) == float('inf'):
			print(-1, end=' ')
		else:
			print(min(i, prev), end=' ')
			prev = min(prev, i)
	print()
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	solve(n, lst)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def chck(mid, ind, n):
	if ind[0] > mid - 1:
		return False
	for i in range(1, len(ind)):
		if ind[i] - ind[i - 1] > mid:
			return False
	curr = ind[len(ind) - 1]
	if n - curr > mid:
		return False
	return True

def solve(case):
	n = int(inp())
	a = lis()
	pos = {}
	for i in range(n):
		if a[i] in pos:
			pos[a[i]].append(i)
		else:
			pos[a[i]] = [i]
	arr = {}
	for i in pos:
		ind = pos[i]
		lo = 1
		hi = n
		ans = n
		while lo <= hi:
			mid = (lo + hi) // 2
			if chck(mid, ind, n):
				ans = min(ans, mid)
				hi = mid - 1
			else:
				lo = mid + 1
		arr[i] = ans
	ans = [0] * (n + 1)
	sl = []
	for i in pos:
		sl.append(i)
	sl = sorted(sl)
	curr = n + 1
	for i in range(len(sl)):
		if arr[sl[i]] < curr:
			for j in range(arr[sl[i]], curr):
				ans[j] = sl[i]
			curr = arr[sl[i]]
		else:
			continue
	for i in range(len(ans)):
		if ans[i] == 0:
			ans[i] = -1
	print(' '.join((str(ans[i]) for i in range(1, len(ans)))))
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	(f, last, ans) = ([0] * (n + 1), [-1] * (n + 1), [-1] * (n + 1))
	for (i, a) in enumerate(A):
		f[a] = max(f[a], i - last[a])
		last[a] = i
	for a in range(1, n + 1):
		f[a] = max(f[a], n - last[a])
	for a in range(1, n + 1):
		i = f[a]
		while i <= n and ans[i] == -1:
			ans[i] = a
			i += 1
	ans = ans[1:]
	print(*ans)


from collections import defaultdict
t = int(input())
for case in range(1, t + 1):
	n = int(input())
	nums = list(map(int, input().split()))
	keys = list(sorted(list(set(nums))))
	indicies = defaultdict(list)
	for (i, v) in enumerate(nums):
		indicies[v].append(i)
	least_k = {}
	best = n + 1
	for key in keys:
		diff_required = max(indicies[key][0] + 1, n - indicies[key][-1])
		for (a, b) in zip(indicies[key][:-1], indicies[key][1:]):
			diff_required = max(diff_required, b - a)
		best = min(best, diff_required)
		least_k[key] = best
	min_val = ['-1'] * n
	current_key_index = len(keys) - 1
	for k in range(1, n + 1):
		while current_key_index >= 0 and least_k[keys[current_key_index]] <= k:
			current_key_index -= 1
		if current_key_index == len(keys) - 1:
			continue
		min_val[k - 1] = str(keys[current_key_index + 1])
	print(' '.join(min_val))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	index = [[0] for _ in range(n + 1)]
	ans = [float('inf')] * (n + 1)
	for i in range(n):
		index[a[i]].append(i + 1)
	for j in range(1, n + 1):
		if len(index[j]) == 1:
			continue
		min_idx = -1
		for k in range(len(index[j]) - 1):
			min_idx = max(index[j][k + 1] - index[j][k], min_idx)
		min_idx = max(min_idx, index[j][1], n - index[j][-1] + 1)
		ans[min_idx] = min(j, ans[min_idx])
	ans2 = [float('inf')]
	for k in range(1, n + 1):
		ans2.append(min(ans2[k - 1], ans[k]))
	for k in range(1, n + 1):
		if ans2[k] == float('inf'):
			ans2[k] = -1
	print(*ans2[1:])


import sys
from copy import *
from bisect import *
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	if len(set(a)) == 1:
		print(*[a[0]] * n)
		continue
	dif = {}
	p = set()
	for i in range(n):
		if a[i] not in dif:
			dif[a[i]] = [-1]
		dif[a[i]].append(i)
		p.add(a[i])
	p = list(p)
	p.sort()
	lo = n + 1
	ans = [-1] * (n + 1)
	for i in p:
		dif[i].append(n)
		maxi = 0
		for j in range(1, len(dif[i])):
			maxi = max(maxi, dif[i][j] - dif[i][j - 1])
		for j in range(maxi, lo):
			ans[j] = i
		lo = min(lo, maxi)
	print(*ans[1:])


import os, sys
from collections import defaultdict, Counter
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		x = defaultdict(lambda : [])
		p = defaultdict(lambda : -1)
		q = defaultdict(lambda : -1)
		for i in range(n):
			x[a[i]].append(i - p[a[i]])
			p[a[i]] = i
		an = 100000000
		for i in x:
			z = max(max(x[i]), n - p[i])
			if q[z] != -1:
				q[z] = min(q[z], i)
			else:
				q[z] = i
		w = -1
		for j in range(1, n + 1):
			if q[j] != -1:
				if w != -1:
					w = min(q[j], w)
				else:
					w = q[j]
			print(w, end=' ')
		print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
sys.setrecursionlimit(200000)
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	res = [-1] * n
	d = collections.defaultdict(list)
	for i in range(n):
		d[arr[i]].append(i)
	for i in d:
		ans = d[i][0] + 1
		for j in range(1, len(d[i])):
			x = d[i][j] - d[i][j - 1]
			if x > ans:
				ans = x
		x = n - d[i][-1]
		if x > ans:
			ans = x
		if res[ans - 1] == -1:
			res[ans - 1] = i
		elif res[ans - 1] > i:
			res[ans - 1] = i
	for i in range(1, n):
		if res[i] == -1 or res[i] > res[i - 1] > 0:
			res[i] = res[i - 1]
	print(' '.join((str(i) for i in res)))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	idx = defaultdict(int)
	dst = defaultdict(int)
	for i in range(n):
		x = a[i]
		if x in idx:
			distance = i - idx[x]
		else:
			distance = i + 1
		if distance > dst[x]:
			dst[x] = distance
		idx[x] = i
	for x in idx:
		distance = n - idx[x]
		if distance > dst[x]:
			dst[x] = distance
	i = 0
	res = []
	m = defaultdict(int)
	for (k, v) in dst.items():
		if m[v] == 0 or k < m[v]:
			m[v] = k
	pr = -1
	result = []
	for x in range(1, n + 1):
		if x in m:
			if pr == -1 or pr > m[x]:
				pr = m[x]
		result += [pr]
	print(' '.join([str(x) for x in result]))


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] -= 1
	miej = [[-1] for i in range(n)]
	for i in range(n):
		miej[l[i]].append(i)
	for i in range(n):
		miej[i].append(n)
	dupa = [0] * n
	for i in range(n):
		k = len(miej[i])
		for j in range(1, k):
			dupa[i] = max(dupa[i], miej[i][j] - miej[i][j - 1])
	cyk = [[dupa[i], i] for i in range(n)]
	cyk.append([1, 1000000])
	cyk.sort()
	odp = [0] * n
	ind = 0
	best = cyk[0][1]
	for k in range(1, n + 1):
		while ind + 1 < n and cyk[ind + 1][0] <= k:
			best = min(best, cyk[ind + 1][1])
			ind += 1
		if best >= 1000000:
			odp[k - 1] = -1
		else:
			odp[k - 1] = best + 1
	print(*odp)


from collections import defaultdict

def read_ints():
	return map(int, input().split())
(t_n,) = read_ints()
for i_t in range(t_n):
	(n,) = read_ints()
	a_seq = tuple(read_ints())
	assert len(a_seq) == n
	indices_by_value = defaultdict(list)
	for (i, a) in enumerate(a_seq):
		indices_by_value[a].append(i)
	min_k_by_value = dict()
	for (value, indices) in indices_by_value.items():
		indices.sort()
		max_k_need = max(indices[0] + 1, n - indices[-1])
		for i_i in range(len(indices) - 1):
			k_need = indices[i_i + 1] - indices[i_i]
			if k_need > max_k_need:
				max_k_need = k_need
		min_k_by_value[value] = max_k_need
	result = [-1] * n
	for (value, k) in min_k_by_value.items():
		i = k - 1
		if result[i] == -1 or result[i] > value:
			result[i] = value
	for i in range(1, n):
		if result[i] == -1 or (result[i - 1] != -1 and result[i] > result[i - 1]):
			result[i] = result[i - 1]
	print(*result)


from collections import defaultdict
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(list)
	for (i, x) in enumerate(arr):
		d[x].append(i)
	l = sorted(d)
	ans = [-1] * (N + 1)
	for x in l:
		ind = d[x]
		space = ind[0] + 1
		for i in range(len(ind) - 1):
			diff = ind[i + 1] - ind[i]
			space = max(space, diff)
		space = max(space, N - ind[-1])
		if ans[space] == -1:
			ans[space] = x
	lo = -1
	for (i, x) in enumerate(ans):
		if lo == -1 or (x != -1 and x < lo):
			lo = x
		ans[i] = lo
	print(' '.join(map(str, ans[1:])))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	dic1 = defaultdict(int)
	dic2 = {}
	lis = list(map(int, input().split()))
	lastocc = {}
	for i in range(len(lis)):
		lastocc[lis[i]] = i
	for i in range(len(lis)):
		if lis[i] not in dic1:
			dic1[lis[i]] = i
			dic2[lis[i]] = i + 1
		else:
			if dic2[lis[i]] < i - dic1[lis[i]]:
				dic2[lis[i]] = i - dic1[lis[i]]
			dic1[lis[i]] = i
	for i in range(len(lis)):
		if dic2[lis[i]] == -1:
			dic2[lis[i]] = max(i + 1, len(lis) - i)
		else:
			dic2[lis[i]] = max(dic2[lis[i]], len(lis) - lastocc[lis[i]])
	dic3 = defaultdict(list)
	for i in dic2:
		dic3[dic2[i]].append(i)
	lis2 = []
	for i in dic3:
		lis2.append(i)
	min1 = float('Inf')
	output = []
	for i in range(1, n + 1):
		if i in dic3:
			min1 = min(min1, min(dic3[i]))
		if min1 == float('Inf'):
			output.append(-1)
		else:
			output.append(min1)
	for i in output:
		print(i, end=' ')
	print()


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	a = rlinput()
	d = defaultdict(list)
	for i in range(n):
		d[a[i]].append(i)
	ans = [-1] * n
	minidx = n
	for i in range(1, n + 1):
		if len(d[i]) == 0:
			continue
		maxdiff = -1
		val = -1
		for j in d[i]:
			maxdiff = max(maxdiff, j - val)
			val = j
		maxdiff = max(maxdiff, n - val)
		if minidx > maxdiff - 1:
			minidx = maxdiff - 1
			ans[minidx] = i
	val = -1
	i = 0
	while i < n:
		if ans[i] == -1:
			ans[i] = val
		else:
			val = ans[i]
		i += 1
	print(*ans)


MAXN = 300005
t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	lst = [0] * (n + 5)
	ai_sep = [-1] * (n + 5)
	for (i, ai) in enumerate(a, 1):
		ai_sep[ai] = ai_sep[ai] if ai_sep[ai] > i - lst[ai] else i - lst[ai]
		lst[ai] = i
	sep_ai = [MAXN] * (n + 5)
	for (ai, sep) in enumerate(ai_sep):
		if sep is -1:
			continue
		sep = ai_sep[ai] = ai_sep[ai] if ai_sep[ai] > n + 1 - lst[ai] else n + 1 - lst[ai]
		sep_ai[sep] = sep_ai[sep] if sep_ai[sep] < ai else ai
	sep_ai[0] = -1
	for sep in range(1, n + 1):
		if sep_ai[sep] == MAXN:
			sep_ai[sep] = sep_ai[sep - 1]
		elif sep_ai[sep - 1] != -1:
			sep_ai[sep] = sep_ai[sep - 1] if sep_ai[sep - 1] < sep_ai[sep] else sep_ai[sep]
	print(*sep_ai[1:n + 1])


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) - 1 for x in input().split()]
	last_occ = [-1 for _ in range(n)]
	max_dist = [float('-inf') for _ in range(n)]
	for (i, x) in enumerate(a):
		max_dist[x] = max(max_dist[x], i - last_occ[x])
		last_occ[x] = i
	for x in a:
		max_dist[x] = max(max_dist[x], n - last_occ[x])
	inverted = [float('inf') for _ in range(n)]
	for x in a:
		inverted[max_dist[x] - 1] = min(inverted[max_dist[x] - 1], x)
	best = float('inf')
	for x in inverted:
		if x != float('inf'):
			best = min(x, best)
		if best == float('inf'):
			print(-1, end=' ')
		else:
			print(best + 1, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
MOD = 10 ** 6

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		lastAppearance = [-1] * n
		maxDist = [-1] * n
		for i in range(n):
			if lastAppearance[a[i] - 1] == -1:
				if maxDist[a[i] - 1] < i + 1:
					maxDist[a[i] - 1] = i + 1
				lastAppearance[a[i] - 1] = i
			else:
				if maxDist[a[i] - 1] < i - lastAppearance[a[i] - 1]:
					maxDist[a[i] - 1] = i - lastAppearance[a[i] - 1]
				lastAppearance[a[i] - 1] = i
		ansTuple = []
		for i in range(n):
			if lastAppearance[i] != -1:
				if maxDist[i] < n - lastAppearance[i]:
					maxDist[i] = n - lastAppearance[i]
				ansTuple.append(maxDist[i] * MOD + i)
		ansTuple.sort()
		ans = [-1] * n
		curAns = -1
		index = 0
		for i in range(n):
			while index < len(ansTuple) and ansTuple[index] // MOD <= i + 1:
				if curAns == -1 or curAns > ansTuple[index] % MOD + 1:
					curAns = ansTuple[index] % MOD + 1
				index += 1
			ans[i] = curAns
		print(' '.join(map(str, ans)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	e = [-1 for i in range(n)]
	for i in range(n):
		if a[i] in d:
			d[a[i]].append(i)
		else:
			d[a[i]] = [-1, i]
	for i in sorted(d):
		d[i].append(n)
		mx = 0
		for j in range(len(d[i]) - 1):
			mx = max(d[i][j + 1] - d[i][j] - 1, mx)
		for k in range(mx, n):
			if e[k] != -1:
				break
			e[k] = i
	print(*e)


import sys
from collections import defaultdict
input = sys.stdin.readline
for k in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		d[l[i]].append(i)
	ans = [n + 1 for _ in range(n + 2)]
	for i in range(1, n + 1):
		maxi = 0
		prev = -1
		for j in d[i]:
			maxi = max(maxi, j - prev)
			prev = j
		maxi = max(maxi, n - prev)
		ans[maxi] = min(ans[maxi], i)
	mini = n + 1
	for i in range(1, n + 1):
		mini = min(mini, ans[i])
		if mini == n + 1:
			print(-1, end=' ')
		else:
			print(mini, end=' ')
	print()


import sys, math
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	i_matrix = [[None if i != 1 else -1 for i in range(2)] for i in range(n + 1)]
	for i in range(n):
		num = arr[i]
		if i_matrix[num][1] == -1:
			i_matrix[num][0] = i + 1
			i_matrix[num][1] = i + 1
		elif i_matrix[num][1] >= i + 1 - i_matrix[num][0]:
			i_matrix[num][0] = i + 1
		else:
			i_matrix[num][1] = i + 1 - i_matrix[num][0]
			i_matrix[num][0] = i + 1
	for i in range(1, n + 1):
		if i_matrix[i][0] != None and i_matrix[i][1] < n + 1 - i_matrix[i][0]:
			i_matrix[i][1] = n + 1 - i_matrix[i][0]
	K_min = [-1 for i in range(n + 1)]
	for i in range(1, n + 1):
		num = i
		if i_matrix[num][1] != -1:
			for i in range(i_matrix[num][1], n + 1):
				if K_min[i] == -1:
					K_min[i] = num
				else:
					break
	[print(i, end=' ') for i in K_min[1:]]
	print()


import sys
input = sys.stdin.readline
from collections import defaultdict
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	pd = defaultdict(int)
	d = defaultdict(int)
	for i in range(N):
		x = X[i]
		d[x] = max(d[x], i + 1 - pd[x])
		pd[x] = i + 1
	rv = defaultdict(lambda : 10 ** 18)
	for key in d:
		d[key] = max(d[key], N + 1 - pd[key])
		rv[d[key]] = min(rv[d[key]], key)
	R = [-1] * N
	mn = 10 ** 18
	for i in range(N):
		if i + 1 in rv:
			mn = min(mn, rv[i + 1])
		if mn != 10 ** 18:
			R[i] = mn
	print(*R)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from bisect import bisect_left as bsl
for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	dict1 = defaultdict(list)
	dict2 = defaultdict(int)
	for s in range(n):
		if len(dict1[vals[s]]) > 0:
			dict2[vals[s]] = max(dict2[vals[s]], s - dict1[vals[s]][-1])
		dict1[vals[s]].append(s)
	info = []
	for s in dict1.keys():
		a0 = max(dict1[s][0] + 1, n - dict1[s][-1])
		dict2[s] = max(dict2[s], a0)
		info.append((dict2[s], s))
	info.sort(key=lambda x: [x[0], x[1]])
	search = [x[0] for x in info]
	minsofar = [info[0][1]]
	for s in range(1, len(info)):
		minsofar.append(min(minsofar[-1], info[s][1]))
	ans = [-1 for s in range(n)]
	for s in range(n):
		ind = min(bsl(search, s + 1), len(search) - 1)
		if search[ind] > s + 1:
			ind -= 1
		if ind >= 0:
			ans[s] = minsofar[ind]
	print(*ans)


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	N = getInt()
	A = getInts()
	ans = [-1] * (N + 1)
	counts = col.defaultdict(list)
	curr_start = N
	for i in range(N):
		counts[A[i]].append(i + 1)
	for i in range(1, N + 1):
		if len(counts[i]) == 0:
			continue
		tmp = list(counts[i])
		best = max(tmp[0], N - tmp[-1] + 1)
		if len(tmp) > 1:
			for j in range(len(tmp) - 1):
				best = max(best, tmp[j + 1] - tmp[j])
		if best > curr_start:
			continue
		for j in range(curr_start, best - 1, -1):
			ans[j] = i
		curr_start = best - 1
		if curr_start == 0:
			break
	print(*ans[1:])
for _ in range(getInt()):
	solve()


maxn = 300000.0 + 5

def solve(arr, n):
	f = [0] * (n + 1)
	last = [0] * (n + 1)
	ans = [-1] * (n + 1)
	for i in range(1, n + 1):
		x = arr[i]
		f[x] = max(f[x], i - last[x])
		last[x] = i
	for x in range(1, n + 1):
		f[x] = max(f[x], n - last[x] + 1)
		i = f[x]
		while i <= n and ans[i] == -1:
			ans[i] = x
			i += 1
	print(*ans[1:])
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = [0] + arr
	solve(arr, n)


def amazing_numbers(n, arr):
	occur_lis = [[] for i in range(n + 1)]
	for index in range(n):
		a = arr[index]
		occur_lis[a].append(index + 1)
	f = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		lis = occur_lis[i]
		if lis != []:
			m = max(lis[0], n - lis[-1] + 1)
			for j in range(len(lis) - 1):
				m = max(m, lis[j + 1] - lis[j])
			f[i] = m
	ans = [-1 for i in range(n + 1)]
	for i in range(1, n + 1):
		if f[i] != 0:
			p = f[i]
			while p < n + 1 and ans[p] == -1:
				ans[p] = i
				p += 1
	return ans[1:]
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = amazing_numbers(n, arr)
	print(' '.join(list(map(str, brr))))


def solve(n, ar):
	pos = [[] for _ in range(n + 1)]
	ans = [n + 1] * (n + 1)
	for i in range(n):
		pos[ar[i]].append(i + 1)
	for i in range(1, n + 1):
		mxgap = -1
		if len(pos[i]) == 0:
			continue
		for j in range(len(pos[i])):
			if j == 0:
				mxgap = max(mxgap, pos[i][j] - 1)
			if j == len(pos[i]) - 1:
				mxgap = max(mxgap, n - pos[i][j])
			if j - 1 >= 0:
				mxgap = max(mxgap, pos[i][j] - pos[i][j - 1] - 1)
		ans[mxgap + 1] = min(ans[mxgap + 1], i)
	track = []
	mini = n + 1
	for i in range(1, n + 1):
		mini = min(mini, ans[i])
		if mini == n + 1:
			track.append(-1)
		else:
			track.append(mini)
	print(' '.join(map(str, track)))
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	solve(n, ar)


from collections import defaultdict
T = int(input())
for t in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	els = sorted(set(A))
	pos = defaultdict(list)
	for (i, el) in enumerate(A):
		pos[el].append(i)
	DMAX = {}
	for el in pos.keys():
		dmax = -1
		arr = [-1] + sorted(pos[el]) + [N]
		for i in range(1, len(arr)):
			dmax = max(dmax, arr[i] - arr[i - 1])
		DMAX[el] = dmax
	ci = 0
	answer = []
	for i in range(N - 1, -1, -1):
		while ci < len(els) and DMAX[els[ci]] > i + 1:
			ci += 1
		if ci >= len(els):
			answer.append(-1)
		else:
			answer.append(els[ci])
	print(' '.join(map(str, answer[::-1])))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	st = 0
	end = n - 1
	ma1 = []
	d = defaultdict(list)
	for i in range(n):
		d[l[i]].append(i)
	u = []
	for i in d:
		m = 0
		d[i].append(n)
		d[i].append(-1)
		d[i].sort()
		for j in range(1, len(d[i])):
			m = max(m, d[i][j] - d[i][j - 1] - 1)
		ma1.append(m)
		u.append(i)
	u = sort_list(u, ma1)
	ma1.sort()
	ans = [-1] * n
	s = [0] * n
	s[0] = u[0]
	for i in range(1, len(u)):
		s[i] = min(s[i - 1], u[i])
	for i in range(n):
		diff = i
		ind = binarySearchCount(ma1, len(ma1), diff)
		if ind != 0:
			ans[i] = s[ind - 1]
	print(*ans)


import sys
import math
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

def inIList():
	return list(map(int, input().split()))

def inSList():
	return input().split()

def solve(n, l):
	ret = []
	m = {}
	for x in range(n):
		if l[x] in m:
			m[l[x]].append(x)
		else:
			m[l[x]] = [x]
	score = {}
	for (k, v) in m.items():
		new_v = [-1] + v + [n]
		diff = 0
		for x in range(1, len(new_v)):
			diff = max(diff, new_v[x] - new_v[x - 1])
		score[k] = diff
	index = {}
	for (k, v) in score.items():
		if v in index:
			index[v] = min(index[v], k)
		else:
			index[v] = k
	index = sorted(index.items())
	table = [index[0]]
	for i in range(1, len(index)):
		table.append((index[i][0], min(index[i][1], table[i - 1][1])))
	table = [(0, -1)] + table
	b = 0
	for k in range(1, n + 1):
		if b + 1 < len(table) and k < table[b + 1][0]:
			print(table[b][1], end=' ')
		else:
			if b + 1 < len(table):
				b += 1
			print(table[b][1], end=' ')
	print()
tasks = inInt()
for t in range(tasks):
	n = inInt()
	l = inIList()
	solve(n, l)


t = int(input())
ans = [[] for i in range(t)]
for i in range(t):
	n = int(input())
	list_a = [*map(int, input().split())]
	dict_a = {value_a: [] for value_a in set(list_a)}
	for j in range(n):
		value = list_a[j]
		dict_a[value].append(j)
	ans_dict_a = {value_a: max([*map(lambda x, y: x - y, dict_a[value_a] + [n], [-1] + dict_a[value_a])]) for value_a in dict_a.keys()}
	ans_list = [-1 for i in range(n)]
	q = n
	for value in sorted(dict_a.keys()):
		p = ans_dict_a[value] - 1
		for k in range(p, q):
			ans_list[k] = value
		if q > p:
			q = p
	ans[i] = ans_list
for an in ans:
	print(' '.join(map(str, an)))


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	q = dd(list)
	w = dd()
	for i in range(n):
		q[a[i]].append(i)
	for i in q:
		e = q[i][0] + 1
		for j in range(1, len(q[i])):
			e = max(e, q[i][j] - q[i][j - 1])
		e = max(e, n - q[i][-1])
		w[i] = e
	r = sorted(w.items(), key=lambda x: x[1])
	t = [-1] * (n + 1)
	j = 0
	k = r[0][0]
	l = r[0][0]
	for i in range(1, n + 1):
		while j < len(r) and r[j][1] == i:
			l = min(r[j][0], l)
			j += 1
		if j != 0:
			t[i] = l
	t.pop(0)
	print(*t)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	C = [0] * (N + 1)
	Last = [-1] * (N + 1)
	A = list(map(int, input().split()))
	for (idx_A, a) in enumerate(A):
		c = idx_A - Last[a]
		if C[a] < c:
			C[a] = c
		Last[a] = idx_A
	for a in range(1, N + 1):
		c = N - Last[a]
		if C[a] < c:
			C[a] = c
	Ans = [-1] * N
	for (a, c) in enumerate(C[1:], 1):
		idx_Ans = c - 1
		while idx_Ans < N and Ans[idx_Ans] == -1:
			Ans[idx_Ans] = a
			idx_Ans += 1
	print(' '.join(map(str, Ans)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	bckt = [-1] * (n + 1)
	last_appearance = [-1] * (n + 1)
	min_subset = [-1] * (n + 1)
	for i in range(n):
		min_subset[a[i]] = max(min_subset[a[i]], i - last_appearance[a[i]])
		last_appearance[a[i]] = i
	for i in range(1, n + 1):
		if last_appearance[i] != -1:
			min_subset[i] = max(min_subset[i], n - last_appearance[i])
	inv = [10 ** 9] * (n + 1)
	for i in range(1, 1 + n):
		if min_subset[i] != -1:
			inv[min_subset[i]] = min(inv[min_subset[i]], i)
	current = inv[0]
	for i in range(1, n + 1):
		if inv[i] < current:
			current = inv[i]
		inv[i] = current
	for i in range(len(inv)):
		if inv[i] == 10 ** 9:
			inv[i] = -1
	print(*inv[1:])


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for (i, v) in enumerate(a):
		if v in d:
			d[v]['max'] = max(d[v]['max'], i - d[v]['pos'])
			d[v]['pos'] = i
		else:
			d[v] = {'max': i + 1, 'pos': i}
	for v in d:
		d[v]['max'] = max(d[v]['max'], n - d[v]['pos'])
	ans = {}
	for v in d:
		m = d[v]['max']
		if m in ans:
			if v < ans[m]:
				ans[m] = v
		else:
			ans[m] = v
	prev = -1
	for i in range(1, n + 1):
		cur = ans.get(i, -1)
		if cur == -1:
			res = prev
		elif prev == -1:
			res = cur
		else:
			res = min(cur, prev)
		prev = res
		print(res, end=' ')
	print()
t = int(input())
for _ in range(t):
	solve()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		idx = [[-1] for _ in range(N + 1)]
		for (i, a) in enumerate(A):
			idx[a].append(i)
		for i in range(N + 1):
			idx[i].append(N)
		ans = [N + 1] * (N + 1)
		for i in range(1, N + 1):
			d = 0
			for j in range(len(idx[i]) - 1):
				d = max(d, idx[i][j + 1] - idx[i][j])
			if d != N + 1:
				ans[d] = min(ans[d], i)
		mi = N + 1
		for i in range(1, N + 1):
			if mi < ans[i]:
				ans[i] = mi
			mi = min(mi, ans[i])
			if ans[i] == N + 1:
				ans[i] = -1
		print(*ans[1:])
main()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	dt = defaultdict(list)
	for (i, v) in enumerate(arr):
		dt[v].append(i)
	ret = [-1 for _ in range(n + 2)]
	for i in range(1, n + 1):
		if i not in dt:
			continue
		tmp = dt[i][0] + 1
		for idx in range(1, len(dt[i])):
			tmp = max(tmp, dt[i][idx] - dt[i][idx - 1])
		tmp = max(tmp, n - dt[i][-1])
		if ret[tmp] == -1:
			ret[tmp] = i
	for i in range(2, n + 1):
		if ret[i - 1] == -1:
			continue
		if ret[i] == -1 or ret[i] > ret[i - 1]:
			ret[i] = ret[i - 1]
	print(' '.join(map(str, ret[1:n + 1])))


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	a = gil()
	idx = {}
	for i in range(n):
		if a[i] not in idx:
			idx[a[i]] = [i]
		else:
			idx[a[i]].append(i)
	ans = [inf] * n
	for v in idx:
		l = idx[v]
		k = max(1, l[0] + 1, n - l[-1])
		for i in range(1, len(l)):
			k = max(k, l[i] - l[i - 1])
		ans[k - 1] = min(v, ans[k - 1])
	for i in range(1, n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		ans[i] = str(ans[i]) if ans[i] != inf else '-1'
	print(' '.join(ans))


def solve(n):
	s = list(map(int, input().split()))
	ind = [[] for _ in range(n + 1)]
	for i in range(n):
		ind[s[i]].append(i)
	ans = [1000000] * (n + 1)
	for i in range(1, n + 1):
		k = 0
		length = len(ind[i])
		if length == 0:
			continue
		for j in range(length - 1):
			k = max(ind[i][j + 1] - ind[i][j], k)
		k = max(n - ind[i][-1], ind[i][0] + 1, k)
		for j in range(k, n + 1):
			if ans[j] <= 300000:
				break
			ans[j] = i
	for i in range(1, n + 1):
		if ans[i] > 300000:
			print(-1, end=' ')
		else:
			print(ans[i], end=' ')
	print()
for _ in range(int(input())):
	n = int(input())
	solve(n)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a
from collections import defaultdict

def solve():
	n = int(input())
	ar = lis()
	temp = [[0] for _ in range(n + 1)]
	for i in range(n):
		temp[ar[i]].append(i + 1)
	for i in range(1, n + 1):
		temp[i].append(n + 1)
	new_temp = [[] for _ in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, len(temp[i])):
			new_temp[i].append(temp[i][j] - temp[i][j - 1])
	ans = [-1] * (n + 1)
	for i in range(1, n + 1):
		t = max(new_temp[i])
		for j in range(t, n + 1):
			if ans[j] != -1:
				break
			ans[j] = i
	print(*ans[1:])
testcase(int(inp()))


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		if a[i] not in d:
			d[a[i]].append(-1)
			d[a[i]].append(i)
		else:
			d[a[i]].append(i)
	s = sorted(d.keys())
	ans = [-1] * (n + 1)
	for el in s:
		mx = 0
		d[el].append(n)
		for i in range(1, len(d[el])):
			mx = max(mx, d[el][i] - d[el][i - 1])
		if ans[mx] == -1:
			ans[mx] = el
		else:
			ans[mx] = min(ans[mx], el)
	f = -1
	for i in range(1, n + 1):
		if ans[i] == -1:
			ans[i] = f
		elif f == -1:
			f = ans[i]
		else:
			ans[i] = min(ans[i], f)
			f = ans[i]
	print(*ans[1:])


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	mp = {}
	for i in range(n):
		mp[a[i]] = [-1, 0]
	for i in range(n):
		mp[a[i]][1] = max(i - mp[a[i]][0], mp[a[i]][1])
		mp[a[i]][0] = i
	for i in range(n):
		mp[a[i]][1] = max(n - mp[a[i]][0], mp[a[i]][1])
	ans = [-1 for x in range(n + 1)]
	for (key, value) in mp.items():
		for i in range(value[1], n + 1):
			if ans[i] <= key and ans[i] != -1:
				break
			if ans[i] == -1:
				ans[i] = key
			else:
				ans[i] = min(ans[i], key)
	for i in range(1, n + 1):
		print(ans[i], end=' ')
	print()


from collections import defaultdict

def function(A):
	n = len(A)
	hash = defaultdict(lambda : [0, -1])
	for i in range(n):
		prev = hash[A[i]][1]
		dist = i - prev
		hash[A[i]] = [max(hash[A[i]][0], dist), i]
	visited = set()
	for i in range(n - 1, -1, -1):
		if A[i] not in visited:
			visited.add(A[i])
			hash[A[i]][0] = max(hash[A[i]][0], n - hash[A[i]][1])
	z = dict()
	for u in hash.keys():
		z[u] = hash[u][0]
	length_to_x = defaultdict(lambda : 2 ** 36)
	for key in z:
		length_to_x[z[key]] = min(length_to_x[z[key]], key)
	res = [2 ** 36 for i in range(n)]
	if len(set(A)) != 1:
		res[0] = 2 ** 36
	else:
		res[0] = A[0]
	for i in range(1, n):
		length = i + 1
		res[i] = res[i - 1]
		if length in length_to_x:
			res[i] = min(res[i], length_to_x[length])
	for i in range(n):
		if res[i] == 2 ** 36:
			res[i] = -1
	return res
t = int(input())
for u in range(t):
	n = int(input())
	A = [int(k) for k in input().split()][:n]
	B = function(A)
	for x in B:
		print(x, '', end='')
	print()


rw = int(input())
for wewq in range(rw):
	n = int(input())
	a = list(map(int, input().split()))
	k = -1
	c = 0
	da = [[c, -1] for i in range(max(a) + 1)]
	for i in range(n):
		da[a[i]][0] = max(i - da[a[i]][1], da[a[i]][0])
		da[a[i]][1] = i
	for i in range(max(a) + 1):
		da[i][0] = max(n - da[i][1], da[i][0])
		da[i][1] = n
	d = [0] * (max(a) + 1)
	for i in range(max(a) + 1):
		d[i] = da[i][0]
	c = 10 ** 9
	lol = [c] * (n + 2)
	for i in range(1, max(a) + 1):
		if lol[d[i]] == c:
			lol[d[i]] = i
	mp = c
	ll = []
	for i in range(n + 1):
		mp = min(lol[i], mp)
		ll.append(mp)
	for i in range(1, n + 1):
		if ll[i] == c:
			print(-1, end=' ')
		else:
			print(ll[i], end=' ')
	print('')


for h in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	dicti = {i: float('inf') for i in range(1, n)}
	last_occ = {}
	for i in range(n):
		if arr[i] not in last_occ:
			dicti[arr[i]] = i + 1
			last_occ[arr[i]] = i
		else:
			dicti[arr[i]] = max(i - last_occ[arr[i]], dicti[arr[i]])
			last_occ[arr[i]] = i
	for i in last_occ:
		dicti[i] = max(dicti[i], n - last_occ[i])
	win_s = {}
	for i in dicti:
		if dicti[i] not in win_s:
			win_s[dicti[i]] = i
		else:
			win_s[dicti[i]] = min(i, win_s[dicti[i]])
	ans = []
	mini = float('inf')
	for i in range(1, n + 1):
		if i in win_s:
			mini = min(mini, win_s[i])
			ans.append(mini)
		elif mini != float('inf'):
			ans.append(mini)
		else:
			ans.append(-1)
	print(*ans)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	n = int(input())
	ans = [-1] * (n + 1)
	arr = list(map(int, input().split()))
	val_with_index = []
	for i in range(0, n):
		val_with_index.append((arr[i], i))
	val_with_index.sort()
	positions = []
	for i in range(0, n):
		positions.append(val_with_index[i][1])
		if i == n - 1 or (i + 1 < n and val_with_index[i][0] != val_with_index[i + 1][0]):
			positions.append(n)
			max_of_min_segment_len = positions[0] + 1
			for j in range(1, len(positions)):
				max_of_min_segment_len = max(max_of_min_segment_len, positions[j] - positions[j - 1])
			for k in range(max_of_min_segment_len, n + 1):
				if ans[k] == -1:
					ans[k] = val_with_index[i][0]
				else:
					break
			positions = []
	print(' '.join(map(str, ans[1:])))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	dict = {}
	for i in range(n):
		if arr[i] in dict:
			dict[arr[i]].append(i)
		else:
			dict[arr[i]] = [-1, i]
	for i in dict:
		dict[i].append(n)
	out = [-1 for x in range(n)]
	for i in sorted(dict.keys()):
		m = -1
		for j in range(len(dict[i]) - 1):
			m = max(m, dict[i][j + 1] - dict[i][j] - 1)
		for j in range(m, n):
			if out[j] != -1:
				break
			out[j] = i
	print(*out)


from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
while t:
	seen = defaultdict(list)
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	best = ()
	for i in range(n):
		seen[a[i]].append(i + 1)
	out = [10 ** 10] * n
	distances = defaultdict(list)
	for key in list(seen.keys()):
		hue = seen[key]
		big = -1
		for i in range(1, len(hue)):
			big = max(hue[i] - hue[i - 1] - 1, big)
		big = max(n - hue[-1], big)
		big = max(hue[0] - 1, big)
		out[big] = min(out[big], key)
	for i in range(1, n):
		out[i] = min(out[i], out[i - 1])
	print(' '.join([str(x) if x != 10 ** 10 else str(-1) for x in out]))
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	g = [[] for i in range(n)]
	a = list(map(int, input().split()))
	ans = [n + 1] * (n + 2)
	for i in range(n):
		a[i] -= 1
		g[a[i]].append(i)
	for x in range(n):
		g[x].append(n)
		lst = -1
		len = 1
		for y in g[x]:
			len = max(len, y - lst)
			lst = y
		if ans[len] > x + 1:
			ans[len] = x + 1
	res = []
	cur = n + 1
	for i in range(1, n + 1):
		cur = min(cur, ans[i])
		ans[i] = cur
		if ans[i] > n:
			ans[i] = -1
		res.append(ans[i])
	print(*res)


t = input()
t = int(t)

def solve(n, arr):
	ans = [float('inf') for _ in range(n)]
	pos = {}
	dist = {}
	for i in range(n):
		pos[arr[i]] = 0
		dist[arr[i]] = 0
	for i in range(n):
		dis = i + 1 - pos[arr[i]]
		dist[arr[i]] = max(dis, dist[arr[i]])
		pos[arr[i]] = i + 1
	for i in range(n):
		dis = n + 1 - pos[arr[i]]
		dist[arr[i]] = max(dis, dist[arr[i]])
	for i in range(n):
		if i + 1 in dist and i + 1 < ans[dist[i + 1] - 1]:
			ans[dist[i + 1] - 1] = i + 1
	seed = ans[0]
	for i in range(1, n):
		if ans[i] < seed:
			seed = ans[i]
		else:
			ans[i] = seed
	for i in range(n):
		if ans[i] == float('inf'):
			ans[i] = -1
	print(*ans)
for i in range(t):
	n = input()
	n = int(n)
	arr = list(map(int, input().split()))
	solve(n, arr)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = Counter(arr)
	if len(count) == n:
		arr.sort()
		ans = [-1] * n
		j = (n + 1) // 2 - 1
		for i in range(n // 2, n):
			ans[i] = arr[j]
			j -= 1
		print(*ans)
		continue
	if len(count) == 1:
		print(*arr)
		continue
	ind = defaultdict(list)
	for i in range(n):
		ind[arr[i]].append(i + 1)
	ind = sorted(ind.items(), key=lambda x: (-len(x[1]), x[0]))
	ans = [-1] * n
	mapka = {i: float('inf') for i in range(1, n + 1)}
	for (k, v) in ind:
		maxgap = max(v[0], n - v[-1] + 1)
		for i in range(len(v) - 1):
			maxgap = max(maxgap, v[i + 1] - v[i])
		mapka[maxgap] = min(k, mapka[maxgap])
	prev = float('inf')
	for (k, v) in mapka.items():
		if v != float('inf'):
			prev = min(prev, v)
			ans[k - 1] = prev
		elif prev == float('inf'):
			ans[k - 1] = -1
		else:
			ans[k - 1] = prev
	ans[n - 1] = min(arr)
	print(*ans)


from collections import defaultdict

def solve(arr):
	n = len(arr)
	lastIndex = defaultdict(lambda : int(-1))
	maxSpan = defaultdict(int)
	for i in range(n):
		maxSpan[arr[i]] = max(maxSpan[arr[i]], i - lastIndex[arr[i]])
		lastIndex[arr[i]] = i
	minPerMaxSpan = defaultdict(lambda : float(float('inf')))
	for (key, val) in maxSpan.items():
		val = max(val, n - lastIndex[key])
		minPerMaxSpan[val] = min(minPerMaxSpan[val], key)
	lastMin = float('inf')
	isSet = False
	ret = []
	for i in range(1, n + 1):
		if i in minPerMaxSpan:
			ret.append(min(lastMin, minPerMaxSpan[i]))
			lastMin = min(minPerMaxSpan[i], lastMin)
			isSet = True
		elif isSet:
			ret.append(lastMin)
		else:
			ret.append(-1)
	return ret
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = solve(arr)
	print(*ans)


import sys
input = sys.stdin.readline
INF = 10 ** 6
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	last_found = [-1] * (n + 1)
	holes = [0] * (n + 1)
	hole_size = [INF] * (n + 1)
	for (i, val) in enumerate(a):
		holes[val] = max(holes[val], i - last_found[val] - 1)
		last_found[val] = i
	for val in range(1, n + 1):
		holes[val] = max(holes[val], n - last_found[val] - 1)
	for (i, item) in enumerate(holes):
		if i == 0:
			continue
		if hole_size[item] != INF:
			continue
		else:
			hole_size[item] = i
	ans = INF
	ret = []
	for i in range(n):
		ans = min(ans, hole_size[i])
		if ans == INF:
			ret.append(-1)
		else:
			ret.append(ans)
	print(*ret)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	min_subsegment = [-1] * (n + 1)
	last_seen = [-1] * (n + 1)
	for i in range(n):
		min_subsegment[a[i]] = max(min_subsegment[a[i]], i - last_seen[a[i]])
		last_seen[a[i]] = i
	for i in range(1, 1 + n):
		min_subsegment[i] = max(min_subsegment[i], n - last_seen[i])
	ans = [10 ** 9] * (n + 1)
	for i in range(1, 1 + n):
		if min_subsegment[i] != n + 1:
			ans[min_subsegment[i]] = min(ans[min_subsegment[i]], i)
	mn = ans[0]
	for i in range(1, 1 + n):
		mn = min(mn, ans[i])
		ans[i] = mn
	for i in range(1, 1 + n):
		if ans[i] == 10 ** 9:
			ans[i] = -1
	print(*ans[1:])


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	idx = defaultdict(list)
	for i in range(1, n + 1):
		idx[i].append(-1)
	for i in range(n):
		idx[a[i]].append(i)
	for i in range(1, n + 1):
		idx[i].append(n)
	ans = [-1] * (n + 1)
	la = n
	for i in range(1, n + 1):
		d = 0
		for j in range(len(idx[i]) - 1):
			d = max(d, idx[i][j + 1] - idx[i][j])
		for j in range(d, la + 1):
			ans[j] = i
		la = min(la, d - 1)
	print(*ans[1:])


import os
from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.readlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx].strip()
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

def problem_solver():

	def solver(inpt):
		MASK = (1 << 19) - 1
		(n,) = inpt.array()
		a = inpt.array()
		b = [a[i] << 19 | i for i in range(n)]
		b.sort()
		c = [-1 for i in range(n)]
		top = n
		le = 0
		ri = 0
		while le < n:
			p = -1
			d = 0
			while ri < n:
				if b[le] >> 19 < b[ri] >> 19:
					break
				q = b[ri] & MASK
				d = max(d, q - p)
				p = q
				ri += 1
			d = max(d, n - p)
			while top >= d:
				c[top - 1] = b[le] >> 19
				top -= 1
			le = ri
		print(*c)
	return solver
try:
	solver = problem_solver()
	for tc in Input().known_tests():
		solver(tc)
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


def sol(a, n):
	pos = [-1] * n
	dist = [-1] * n
	for i in range(len(a)):
		c = a[i] - 1
		dist[c] = max(dist[c], i - pos[c] - 1)
		pos[c] = i
	for i in range(n):
		if dist[i] != -1:
			dist[i] = max(dist[i], n - pos[i] - 1)
	re = [-1] * n
	for i in range(n):
		if dist[i] != -1:
			begin = dist[i]
			while begin < n and re[begin] == -1:
				re[begin] = i + 1
				begin += 1
	return re
tc = int(input())
for _ in range(tc):
	n = int(input())
	a = list(map(lambda x: int(x), input().split(' ')))
	re = sol(a, n)
	print(*re, sep=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = [-1] * n
	l2 = [-1] * n
	for i in range(n):
		if l[a[i] - 1] == -1:
			l[a[i] - 1] = i
		else:
			l2[a[i] - 1] = max(l2[a[i] - 1], i - l[a[i] - 1] - 1)
			l[a[i] - 1] = i
	for i in range(n):
		if l2[a[i] - 1] == -1:
			l2[a[i] - 1] = max(i, n - i - 1)
	l3 = [-1] * n
	for i in range(n):
		if l3[a[i] - 1] == -1:
			l3[a[i] - 1] = i
	for i in range(n):
		if not l[i] == -1:
			l2[i] = max(l2[i], n - l[i] - 1)
		if not l3[i] == -1:
			l2[i] = max(l2[i], l3[i])
	ans = [float('inf')] * n
	for i in range(n):
		ans[l2[i]] = min(ans[l2[i]], i + 1) if l2[i] != -1 else ans[l2[i]]
	for i in range(1, n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		if ans[i] == float('inf'):
			ans[i] = -1
	print(*ans)


import collections

def amaze(arr):
	lastSeen = collections.defaultdict(int)
	maxDists = collections.defaultdict(int)
	for i in range(len(arr)):
		if arr[i] in lastSeen:
			maxDists[arr[i]] = max(maxDists[arr[i]], i - lastSeen[arr[i]])
		else:
			maxDists[arr[i]] = i + 1
		lastSeen[arr[i]] = i
	for key in lastSeen:
		maxDists[key] = max(maxDists[key], len(arr) - lastSeen[key])
	if len(maxDists) == 1:
		return [arr[0]] * len(arr)
	ans = [float('inf')] * len(arr)
	for key in maxDists:
		ans[maxDists[key] - 1] = min(ans[maxDists[key] - 1], key)
	for i in range(1, len(ans)):
		ans[i] = min(ans[i - 1], ans[i])
	for i in range(len(ans)):
		if ans[i] == float('inf'):
			ans[i] = -1
	return ans
T = int(input())
for t in range(T):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	ans = amaze(arr)
	print(' '.join([str(i) for i in ans]))


from collections import defaultdict

def main():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		d = defaultdict(list)
		for x in range(n):
			d[l[x]].append(x)
		ans = [-1] * n
		for x in d:
			temp = [-1] + d[x] + [n]
			mi = 0
			for y in range(len(temp) - 1):
				mi = max(mi, temp[y + 1] - temp[y])
			if mi != 0:
				if ans[mi - 1] != -1:
					if ans[mi - 1] > x:
						ans[mi - 1] = x
				else:
					ans[mi - 1] = x
		temp = -1
		for x in range(n):
			if ans[x] == -1:
				ans[x] = temp
			else:
				if temp == -1:
					temp = ans[x]
				else:
					temp = min(ans[x], temp)
				ans[x] = temp
		print(*ans)
main()


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	S = {}
	for el in arr:
		S[el] = [0]
	for i in range(len(arr)):
		S[arr[i]].append(i + 1)
	G = {}
	for key in S:
		S[key].append(n + 1)
		best = 0
		for i in range(len(S[key]) - 1):
			gap = abs(S[key][i] - S[key][i + 1])
			best = max(gap, best)
		G[key] = best
	B = {}
	for key in G:
		l = G[key]
		if l not in B:
			B[l] = key
		else:
			B[l] = min(B[l], key)
	ans = []
	for key in B:
		ans.append((key, B[key]))
	ans.sort()
	pp = []
	low = 9999999999999999
	j = 0
	for i in range(1, n + 1):
		if j < len(ans) and i == ans[j][0]:
			if ans[j][1] < low:
				low = ans[j][1]
			j += 1
		if low > 10 ** 10:
			pp.append(-1)
		else:
			pp.append(low)
	print(*pp)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	check = [0] * (n + 1)
	last = [0] * (n + 1)
	ans = [-1] * (n + 1)
	for i in range(n):
		check[a[i]] = max(check[a[i]], i - last[a[i]] + 1)
		last[a[i]] = i + 1
	for i in range(1, n + 1):
		check[i] = max(check[i], n - last[i] + 1)
		j = check[i]
		while j <= n and ans[j] == -1:
			ans[j] = i
			j += 1
	print(*ans[1:])


import sys
input = sys.stdin.readline

def solve_slow(A, n):
	ans = [-1 for _ in range(n)]
	for k in range(n):
		common = set(A[:k + 1])
		for i in range(n - k):
			common &= set(A[i:i + k + 1])
		if common:
			ans = [-1 for _ in range(n)]
	for k in range(n):
		common = set(A[:k + 1])
		for i in range(n - k):
			common &= set(A[i:i + k + 1])
		if common:
			ans[k] = min(common)
	return ans

def solve_fast(A, n):
	ans = [-1 for _ in range(n)]
	counter = {}
	for (index, a) in enumerate(A):
		if a not in counter:
			counter[a] = [index]
		else:
			counter[a].append(index)
	for i in range(1, n + 1):
		if i not in counter:
			continue
		indices = counter[i]
		indices.sort()
		segment_size = max(indices[0] + 1, n - indices[-1])
		for j in range(len(indices) - 1):
			diff = indices[j + 1] - indices[j]
			segment_size = max(segment_size, diff)
		if ans[segment_size - 1] == -1:
			ans[segment_size - 1] = i
	for i in range(1, n):
		if ans[i - 1] == -1:
			continue
		if ans[i] == -1 or ans[i - 1] < ans[i]:
			ans[i] = ans[i - 1]
	return ans
t = int(input())
for x in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	ans = solve_fast(A, n)
	print(' '.join(map(str, ans)))


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = [''] * t
	inf = 10 ** 9
	for ti in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		longest = [-1] * (n + 1)
		prev = [-1] * (n + 1)
		for (i, x) in enumerate(a):
			longest[x] = max(longest[x], i - prev[x])
			prev[x] = i
		ans = [inf] * (n + 2)
		for i in range(n, 0, -1):
			longest[i] = max(longest[i], n - prev[i])
			ans[longest[i]] = i
		for i in range(1, n + 1):
			ans[i + 1] = min(ans[i], ans[i + 1])
			if ans[i] == inf:
				ans[i] = -1
		ans_a[ti] = ' '.join(map(str, ans[1:-1]))
	output(*ans_a)
main()


from collections import defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for (i, v) in enumerate(a):
		d[v].append(i + 1)
	V = list(d.keys())
	V.sort()
	mint = [n + 1] * (n + 1)
	for v in V:
		L = d[v]
		sub_max = L[0]
		L.append(n + 1)
		for i in range(len(L) - 1):
			sub_max = max(sub_max, L[i + 1] - L[i])
		mint[sub_max] = min(v, mint[sub_max])
	for i in range(1, n + 1):
		mint[i] = min(mint[i], mint[i - 1])
	res = []
	for i in range(1, n + 1):
		if mint[i] == n + 1:
			res.append(-1)
		else:
			res.append(mint[i])
	print(*res)
	return

def main():
	T = int(input())
	for i in range(T):
		solve()
	return
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = ria()
		dc = Counter(a)
		z = deque(sorted(list(set(a))))
		dg = {}
		for i in range(n):
			if a[i] in dg:
				dg[a[i]].append(i)
			else:
				dg[a[i]] = [i]
		mdg = {}
		for i in dg:
			ni = [-1] + dg[i] + [n]
			mgap = 0
			for j in range(1, len(ni)):
				mgap = max(mgap, ni[j] - ni[j - 1])
			mdg[i] = mgap - 1
		ans = [0] * n
		for k in range(n, 0, -1):
			while len(z) > 0:
				if mdg[z[0]] <= k - 1 and n // k <= dc[z[0]]:
					ans[k - 1] = z[0]
					break
				else:
					z.popleft()
			if len(z) == 0:
				ans[k - 1] = -1
		print(*ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		d[a[i]].append(i)
	x = []
	for i in d:
		m = 0
		for j in range(len(d[i])):
			if j == 0:
				m = max(m, d[i][j] + 1)
			if j == len(d[i]) - 1:
				m = max(m, n - d[i][j])
				m = max(m, d[i][j] - d[i][j - 1])
			else:
				m = max(m, d[i][j] - d[i][j - 1])
		x.append([m, i])
	x = sorted(x, key=lambda x: (x[0], x[1]))
	for i in range(1, len(x)):
		x[i][1] = min(x[i][1], x[i - 1][1])
	d = {}
	for i in range(len(x)):
		y = d.get(x[i][0], 10 ** 9)
		d[x[i][0]] = min(y, x[i][1])
	ans = [-1] * n
	j = 0
	for i in range(1, n + 1):
		y = d.get(i, -1)
		if y == -1:
			ans[i - 1] = ans[i - 2]
		else:
			ans[i - 1] = y
	sys.stdout.write(' '.join(map(str, ans)) + '\n')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from collections import defaultdict

def gift():
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		lis = [0] * (n + 1)
		md = [float('-inf')] * (n + 1)
		for i in range(n):
			md[a[i]] = max(md[a[i]], i + 1 - lis[a[i]])
			lis[a[i]] = i + 1
		for i in range(n + 1):
			md[i] = max(md[i], n + 1 - lis[i])
		itr = n - 1
		ans = [-1] * n
		for i in range(1, n + 1):
			while md[i] <= itr + 1:
				ans[itr] = i
				itr -= 1
		yield ' '.join((str(x) for x in ans))
t = int(input())
ans = gift()
print(*ans, sep='\n')


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) - 1 for a in input().split()]
	X = [-1] * N
	Y = [0] * N
	for (i, a) in enumerate(A):
		Y[a] = max(Y[a], i - X[a] - 1)
		X[a] = i
	for i in range(N):
		Y[i] = max(Y[i], N - X[i] - 1)
	ANS = [N + 1] * (N + 1)
	for (i, a) in enumerate(Y):
		ANS[a] = min(ANS[a], i + 1)
	for i in range(1, N + 1):
		ANS[i] = min(ANS[i], ANS[i - 1])
	print(*[a if a <= N else -1 for a in ANS[:-1]])


from collections import defaultdict, Counter
from math import log, ceil, floor

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : [-1])
	for i in range(n):
		d[a[i]].append(i)
	for i in d.keys():
		d[i].append(n)
	l = sorted(set(a), reverse=True)
	res = [-1 for i in range(n)]
	for i in l:
		m = -float('inf')
		li = d[i]
		for j in range(1, len(li)):
			m = max(m, li[j] - li[j - 1])
		res[m - 1] = i
	prev = -1
	for i in range(n):
		if res[i] != -1:
			if prev == -1:
				prev = res[i]
			else:
				prev = min(res[i], prev)
		if res[i] == -1:
			res[i] = prev
		elif res[i] > prev and prev != -1:
			res[i] = prev
	print(*res)
t = 1
t = int(input())
for _ in range(t):
	solve()


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, stdin.readline().split()))
	s = []
	for i in range(n):
		s.append([-1, -1])
	for i in range(n):
		s[arr[i] - 1][0] = max(s[arr[i] - 1][0], i - s[arr[i] - 1][1] - 1)
		s[arr[i] - 1][1] = i
	for i in range(n):
		s[i][0] = max(s[i][0], n - s[i][1] - 1)
	ans = [-1] * n
	for i in range(n):
		for j in range(s[i][0], n):
			if ans[j] != -1:
				break
			else:
				ans[j] = i + 1
	for i in ans:
		stdout.write(str(i) + ' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [0] * (n + 1)
	dis = [-1] + [-1] * n
	ans = [-1] * (n + 1)
	count = 0
	tt = 0
	for i in range(n):
		if l[i] != l[0] and l1[l[i]] == 0:
			dis[l[i]] = max(dis[l[i]], i - l1[l[i]] + 1)
			l1[l[i]] = i
		else:
			dis[l[i]] = max(dis[l[i]], i - l1[l[i]])
			l1[l[i]] = i
	for i in range(1, n + 1):
		if l[-1] != i and dis[i] != -1:
			dis[i] = max(dis[i], n - l1[i])
	d = min(dis)
	c = dis.index(min(dis))
	for i in range(1, n + 1):
		if dis[i] != -1:
			if ans[dis[i]] == -1:
				ans[dis[i]] = i
			else:
				ans[dis[i]] = min(ans[dis[i]], i)
	c = -1
	for i in range(1, n + 1):
		if ans[i] != -1:
			if c != -1:
				if c > ans[i]:
					c = ans[i]
			else:
				c = ans[i]
		print(c, end=' ')
	print()


import sys
from _collections import deque
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	v = {}
	ans = deque([])
	for (it, i) in enumerate(a):
		d[i] = d.get(i, [0])
		d[i].append(it + 1)
		v[i] = max(d[i][-1] - d[i][-2], v.get(i, it + 1))
	for i in v:
		v[i] = max(v[i], n - d[i][-1] + 1)
	for i in sorted(v):
		if v[i] <= n:
			while n >= v[i]:
				ans.appendleft(i)
				n -= 1
		if not n:
			break
	if n:
		while n >= 1:
			ans.appendleft(-1)
			n -= 1
	print(*ans)


from collections import defaultdict, Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	fans = [-1 for a in range(1, n + 1)]
	fans[-1] = min(arr)
	fr = defaultdict(list)
	for a in range(n):
		if len(fr[arr[a]]) == 0:
			fr[arr[a]].append(-1)
		fr[arr[a]].append(a)
	for a in fr.keys():
		fr[a].append(n)
	kr = sorted(fr.keys())
	for a in kr:
		ma = -1
		li = fr[a]
		for ab in range(len(li) - 1):
			ma = max(ma, li[ab + 1] - li[ab])
		if fans[ma - 1] == -1:
			fans[ma - 1] = a
	mi = 10000000
	for a in range(n):
		if fans[a] == -1 and mi == 10000000:
			continue
		elif fans[a] == -1:
			fans[a] = mi
		elif mi < fans[a]:
			fans[a] = mi
		else:
			mi = fans[a]
	print(*fans)


t = int(input())
INF = 10 ** 18
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if n == 1:
		print(A[0])
		continue
	d = {}
	max_ = {}
	f = {}
	for (i, a) in enumerate(A):
		if a in d:
			max_[a] = max(i - d[a], max_[a])
			d[a] = i
		else:
			max_[a] = 0
			d[a] = i
			f[a] = i
	for a in max_:
		if max_[a] == 0:
			max_[a] = max(d[a] + 1, n - d[a])
		else:
			max_[a] = max(max_[a], f[a] + 1, n - d[a])
	ans = [INF] * n
	for (k, v) in max_.items():
		ans[v - 1] = min(k, ans[v - 1])
	for i in range(1, n):
		ans[i] = min(ans[i - 1], ans[i])
	for i in range(n):
		if ans[i] == INF:
			ans[i] = -1
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	last = [-1 for i in range(n + 1)]
	gap = [0 for i in range(n + 1)]
	for i in range(n):
		gap[a[i]] = max(gap[a[i]], i - last[a[i]])
		last[a[i]] = i
	for i in range(1, n + 1):
		gap[i] = max(gap[i], n - last[i])
	candidates = [float('inf') for i in range(n + 2)]
	for i in range(1, n + 1):
		candidates[gap[i]] = min(candidates[gap[i]], i)
	mini = float('inf')
	for k in range(1, n + 1):
		mini = min(mini, candidates[k])
		if mini == float('inf'):
			print(-1, end=' ')
		else:
			print(mini, end=' ')
	print()


t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [-1 for j in range(n + 3)]
	d = {}
	la = l[-1]
	f = l[0]
	for j in range(n):
		if l[j] not in d:
			d[l[j]] = []
			if f != l[j]:
				d[l[j]].append(-1)
		d[l[j]].append(j)
	for k in d:
		m = 0
		if k != la:
			d[k].append(n)
		for j in range(len(d[k]) - 1):
			if d[k][j + 1] - d[k][j] > m:
				m = d[k][j + 1] - d[k][j]
		if ans[m] == -1:
			ans[m] = k
		else:
			ans[m] = min(ans[m], k)
	m = n
	a = False
	for j in range(1, n + 1):
		if ans[j] != -1:
			m = min(m, ans[j])
			a = True
		if a:
			ans[j] = m
	print(*ans[1:n + 1])


INF = 10 ** 9
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	vals = [[-1] for i in range(n + 1)]
	for (i, val) in enumerate(a):
		vals[val].append(i)
	ans = [INF] * (n + 1)
	for (val, tmp) in enumerate(vals):
		length = 0
		tmp.append(n)
		if len(tmp) == 2:
			continue
		for i in range(len(tmp) - 1):
			length = max(tmp[i + 1] - tmp[i], length)
		if length == 0:
			continue
		ans[length] = min(val, ans[length])
	for i in range(n):
		ans[i + 1] = min(ans[i], ans[i + 1])
		if ans[i] == INF:
			ans[i] = -1
	print(*ans[1:])


from collections import *
from itertools import *
from bisect import *

def inp():
	return int(input())

def arrinp():
	return [int(x) for x in input().split()]

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		A = [0] + arrinp()
		ans = [-1 for i in range(n + 1)]
		F = [0 for i in range(n + 1)]
		last = [0 for i in range(n + 1)]
		for i in range(1, n + 1):
			x = A[i]
			F[x] = max(F[x], i - last[x])
			last[x] = i
		for x in range(1, n + 1):
			F[x] = max(F[x], n - last[x] + 1)
			for k in range(F[x], n + 1):
				if ans[k] == -1:
					ans[k] = x
				else:
					break
		print(*ans[1:], sep=' ')
main()


import sys
import itertools as it
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	f = cc.defaultdict(int)
	ff = cc.defaultdict(int)
	for i in l:
		if not f[i]:
			f[i] = -1
	for i in range(n):
		ff[l[i]] = max(ff[l[i]], i - f[l[i]])
		f[l[i]] = i
	for i in set(l):
		ff[i] = max(ff[i], n - f[i])
	ans = [-1] * n
	for i in sorted(set(l), reverse=True):
		d = ff[i]
		ans[d - 1] = i
	for i in range(n - 1):
		if ans[i] != -1:
			if ans[i + 1] == -1 or ans[i + 1] > ans[i]:
				ans[i + 1] = ans[i]
	print(*ans)


import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	a = Read.list_int()
	tmp = {}
	last = {}
	for i in range(n):
		v = i
		if a[i] in last:
			v = i - last[a[i]] - 1
		last[a[i]] = i
		if a[i] in tmp:
			if v > tmp[a[i]]:
				tmp[a[i]] = v
		else:
			tmp[a[i]] = v
	for (k, v) in last.items():
		v = n - 1 - v
		if v > tmp[k]:
			tmp[k] = v
	tmp_s = sorted(list(tmp.keys()))
	res = []
	l = 0
	for i in tmp_s:
		r = n - tmp[i]
		for j in range(l, r):
			res.append(str(i))
		if r > l:
			l = r
	for i in range(n - len(res)):
		res.append('-1')
	res.reverse()
	print(' '.join(res))
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


from __future__ import division, print_function
from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		d = defaultdict(list)
		for x in range(n):
			d[l[x]].append(x)
		ans = [-1] * n
		for x in d:
			temp = [-1] + d[x] + [n]
			mi = 0
			for y in range(len(temp) - 1):
				mi = max(mi, temp[y + 1] - temp[y])
			if mi != 0:
				if ans[mi - 1] != -1:
					if ans[mi - 1] > x:
						ans[mi - 1] = x
				else:
					ans[mi - 1] = x
		temp = -1
		for x in range(n):
			if ans[x] == -1:
				ans[x] = temp
			else:
				if temp == -1:
					temp = ans[x]
				else:
					temp = min(ans[x], temp)
				ans[x] = temp
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import defaultdict
for _ in range(int(read())):
	n = int(read())
	nums = list(readi())
	count = defaultdict(int)
	maxDist = defaultdict(int)
	lastIndex = defaultdict(int)
	for num in nums:
		lastIndex[num] = -1
	for (i, num) in enumerate(nums):
		count[num] += 1
		if num in lastIndex:
			maxDist[num] = max(i - lastIndex[num], maxDist[num])
		lastIndex[num] = i
	for num in nums:
		maxDist[num] = max(n - lastIndex[num], maxDist[num])
	ansDict = defaultdict(list)
	for num in maxDist.keys():
		k = n // maxDist[num]
		if count[num] >= k:
			ansDict[maxDist[num]].append(num)
	ansList = [-1] * n
	lastMin = float('inf')
	for i in range(1, n + 1):
		if i in ansDict:
			lastMin = min(lastMin, min(ansDict[i]))
		ansList[i - 1] = lastMin if lastMin != float('inf') else -1
	print(' '.join(map(str, ansList)))


maxn = 300000.0 + 5

def solve(arr, n):
	f = [0] * (n + 1)
	last = [0] * (n + 1)
	ans = [-1] * (n + 1)
	for i in range(1, n + 1):
		x = arr[i]
		f[x] = max(f[x], i - last[x])
		last[x] = i
	for x in range(1, n + 1):
		f[x] = max(f[x], n - last[x] + 1)
		i = f[x]
		while i <= n and ans[i] == -1:
			ans[i] = x
			i += 1
	print(*ans[1:])
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = [0] + arr
	solve(arr, n)
num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


a = int(input())
from collections import *
for i in range(a):
	n = int(input())
	z = list(map(int, input().split()))
	dl = defaultdict(int)
	al = defaultdict(list)
	for i in range(len(z)):
		al[z[i]].append(i)
	ans = [n + 1 for i in range(n)]
	for i in al:
		m = [0] + al[i] + [n]
		maxa = 0
		for q in range(1, len(m)):
			if q == 1:
				maxa = max(maxa, m[q] + 1)
				continue
			maxa = max(maxa, m[q] - m[q - 1])
		ans[i - 1] = maxa
	tp = []
	for i in range(len(ans)):
		tp.append([ans[i], i + 1])
	tp.sort()
	index = 1
	fin = []
	r = 0
	for i in range(1, len(tp)):
		tp[i][1] = min(tp[i - 1][1], tp[i][1])
	index = 0
	for i in range(1, tp[0][0]):
		fin.append(-1)
	for j in range(len(tp)):
		if j < len(tp) - 1:
			for x in range(tp[j][0], tp[j + 1][0]):
				fin.append(tp[j][1])
		else:
			for x in range(tp[j][0], n):
				fin.append(tp[j][1])
	while len(fin) != n:
		fin.append(tp[-1][1])
	print(*fin)


from collections import defaultdict
from sys import stdin
input = stdin.readline

def put():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(put())
	reach = defaultdict()
	prev = defaultdict()
	s = set(l)
	for i in s:
		reach[i] = 0
		prev[i] = -1
	for (i, v) in enumerate(l):
		reach[v] = max(reach[v], i - prev[v])
		prev[v] = i
	for i in s:
		reach[i] = max(reach[i], n - prev[i])
	ans = [n + 1] * n
	for (v, dis) in reach.items():
		ans[dis - 1] = min(ans[dis - 1], v)
	for i in range(1, n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		if ans[i] == n + 1:
			ans[i] = -1
	print(*ans)


t = int(input())
for w in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	d = {}
	for (i, x) in enumerate(a):
		if x not in d:
			d[x] = [i + 1, i + 1]
		else:
			d[x] = [i + 1, max(d[x][1], i + 1 - d[x][0])]
	l = len(a) + 1
	for i in d:
		d[i] = max(d[i][1], l - d[i][0])
	z = {}
	for (i, x) in d.items():
		if x in z:
			if z[x] > i:
				z[x] = i
		else:
			z[x] = i
	q = [-1 for x in range(n)]
	for (i, x) in z.items():
		q[i - 1] = x
	q1 = []
	m = -1
	for x in q:
		if x == -1:
			q1.append(m)
		else:
			if m != -1:
				m = min(m, x)
			else:
				m = x
			q1.append(m)
	print(' '.join((str(x) for x in q1)))


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
for _ in range(rn()):
	n = rn()
	l = rl()
	ans = n * [-1]
	a = max(l) * [-1]
	d = max(l) * [0]
	for i in range(n):
		d[l[i] - 1] = max(d[l[i] - 1], i - a[l[i] - 1])
		a[l[i] - 1] = i
	for i in range(max(l)):
		d[i] = max(d[i], n - a[i])
	for i in set(sorted(l)):
		if ans[d[i - 1] - 1] == -1:
			ans[d[i - 1] - 1] = i
		else:
			ans[d[i - 1] - 1] = min(i, ans[d[i - 1] - 1])
	m = float('inf')
	i = 0
	while i < n and ans[i] == -1:
		i += 1
	m = ans[i]
	for j in range(i, n):
		if ans[j] == -1:
			ans[j] = m
		else:
			ans[j] = min(ans[j], m)
		m = min(m, ans[j])
	print(' '.join(list(map(str, ans))))


import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, ls) = (int(input()), list(map(int, input().split())))
	(last, dis) = ([0] * (n + 1), [0] * (n + 1))
	for (i, u) in enumerate(ls):
		i += 1
		dis[u] = max(dis[u], i - last[u])
		last[u] = i
	for u in range(n + 1):
		dis[u] = max(dis[u], n + 1 - last[u])
	mnk = [n + 1] * (n + 2)
	for (i, u) in enumerate(dis):
		mnk[u] = min(mnk[u], i)
	(res, pr) = ([], n + 1)
	for i in range(1, n + 1):
		pr = min(pr, mnk[i])
		res.append(-1 if pr == n + 1 else pr)
	print(*res)


def solve(n, a):
	maxD = [1] * (n + 1)
	lastP = [-1] * (n + 1)
	for i in range(n):
		d = i - lastP[a[i]]
		maxD[a[i]] = max(maxD[a[i]], d)
		lastP[a[i]] = i
	res = [-1] * n
	k = n
	for v in range(1, n + 1):
		if lastP[v] == -1:
			continue
		minK = max(maxD[v], n - lastP[v])
		while k >= minK:
			res[k - 1] = v
			k -= 1
	return res
tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	print(*solve(n, a))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 300005
	f1 = {}
	f2 = {}
	ans = [x] * n
	for i in range(n):
		f1[a[i]] = -1
		f2[a[i]] = 0
	for i in range(n):
		f2[a[i]] = max(f2[a[i]], i - f1[a[i]])
		f1[a[i]] = i
	for i in range(n):
		f2[a[i]] = max(f2[a[i]], n - f1[a[i]])
	for i in range(n):
		ans[f2[a[i]] - 1] = min(a[i], ans[f2[a[i]] - 1])
	ans[-1] = min(a)
	for i in range(1, n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		if ans[i] == x:
			ans[i] = -1
	print(*ans)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	q = list(map(int, sys.stdin.readline().split()))
	(clovar, p, x) = ({}, [], 1000000000.0)
	for i in range(n):
		if q[i] in clovar:
			clovar[q[i]].append(i)
		else:
			clovar[q[i]] = [i]
	for o in clovar:
		t = clovar[o]
		ma = max(t[0] + 1, n - t[-1])
		dlinat = len(t) - 1
		for i in range(dlinat):
			ma = max(t[i + 1] - t[i], ma)
		p.append([ma, o])
	p.sort()
	ans = [p[0]]
	dlinap = len(p)
	for i in range(1, dlinap):
		if ans[-1][0] != p[i][0]:
			ans.append(p[i])
	ans.append([n + 1, 1000000000.0])
	dlina_1 = ans[0][0] - 1
	print(*[-1 for i in range(dlina_1)], end=' ')
	dlinaans = len(ans) - 1
	for i in range(dlinaans):
		x = min(x, ans[i][1])
		dlinax = ans[i + 1][0] - ans[i][0]
		print(*[x for o in range(dlinax)], end=' ')
	print()
for i in range(int(sys.stdin.readline().strip())):
	main()


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, -1)
	rast = dict()
	last = dict()
	for i in range(1, n + 1):
		x = a[i]
		ll = last.get(x, -1)
		if ll == -1:
			last[x] = i
			rast[x] = i
		else:
			r = i - ll
			if r > rast[x]:
				rast[x] = r
			last[x] = i
	ans = [-1] * (n + 1)
	for h in rast:
		lb = n + 1 - last[h]
		if lb > rast[h]:
			rast[h] = lb
		r = rast[h]
		if ans[r] == -1:
			ans[r] = h
		elif ans[r] > h:
			ans[r] = h
	for k in range(2, n + 1):
		if (ans[k] > ans[k - 1] or ans[k] == -1) and ans[k - 1] != -1:
			ans[k] = ans[k - 1]
	print(*ans[1:])


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()

def pr(*args, end='\n'):
	for _arg in args:
		sys.stdout.write(str(_arg) + ' ')
	sys.stdout.write(end)
inf = float('inf')
from collections import defaultdict
_T_ = inin()
for _t_ in range(_T_):
	N = inin()
	A = inar()
	valToIndices = defaultdict(list)
	for (i, x) in enumerate(A):
		valToIndices[x].append(i)
	valToGap = {}
	for (x, indices) in valToIndices.items():
		maxGap = max(indices[0] + 1, N - indices[-1])
		for (i, j) in zip(indices, indices[1:]):
			maxGap = max(maxGap, j - i)
		valToGap[x] = maxGap
	best = [inf] * (N + 1)
	for (k, v) in valToGap.items():
		best[v] = min(best[v], k)
	for (k, b) in enumerate(best):
		if k >= 1:
			best[k] = min(best[k - 1], b)
	ans = [-1 if x == inf else x for x in best][1:]
	pr(' '.join(map(str, ans)))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	out = [-1] * n
	b = {}
	for i in range(n):
		if a[i] in b:
			b[a[i]].append(i)
		else:
			b[a[i]] = [-1, i]
	for i in b:
		b[i].append(n)
	for i in b:
		m = -1
		lbi = len(b[i])
		v1 = max([b[i][j] - b[i][j - 1] - 1 for j in range(1, lbi)])
		b[i] = max(m, v1)
	a = {i: 10 ** 6 for i in b.values()}
	for i in b:
		a[b[i]] = min(a[b[i]], i)
	b = [-1] * (n + 1)
	for i in range(n):
		if i in a:
			b[i + 1] = min(b[i], a[i]) if b[i] > 0 else a[i]
		else:
			b[i + 1] = b[i]
	print(*b[1:])


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	dct = {}
	for i in a:
		dct[i] = (-1, 0)
	now = 0
	for i in a:
		dct[i] = [now, max(dct[i][1], now - dct[i][0])]
		now += 1
	for i in dct:
		dct[i] = max(dct[i][1], n - dct[i][0])
	a = [(dct[i], i) for i in dct]
	a.sort()
	mini = 1000000000000000
	now = 0
	q = len(a)
	for i in range(1, n + 1):
		while now < q and a[now][0] == i:
			mini = min(mini, a[now][1])
			now += 1
		if mini == 1000000000000000:
			print(-1, end=' ')
		else:
			print(mini, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	d = {}
	for i in range(n):
		if l[i] not in d:
			d[l[i]] = [i + 1]
		else:
			temp = d[l[i]]
			temp.append(i + 1)
			d[l[i]] = temp
	for i in d:
		d[i].append(n + 1)
	for i in d:
		temp = d[i]
		arr = [0] * len(temp)
		arr[0] = temp[0]
		for j in range(1, len(temp)):
			arr[j] = temp[j] - temp[j - 1]
		d[i] = arr
	newdic = {}
	for i in d:
		newdic[i] = max(d[i])
	index = {}
	for i in newdic:
		if newdic[i] in index:
			index[newdic[i]].append(i)
		else:
			index[newdic[i]] = [i]
	ans = [0] * (n + 1)
	for i in range(1, n + 1):
		if i not in index:
			if ans[i - 1] == 0:
				ans[i] = -1
			else:
				ans[i] = ans[i - 1]
		elif ans[i - 1] > 0:
			ans[i] = min(min(index[i]), ans[i - 1])
		else:
			ans[i] = min(index[i])
	for i in range(1, n + 1):
		print(ans[i], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	last = [-1 for i in range(n + 1)]
	gap = [0 for i in range(n + 1)]
	for i in range(n):
		gap[a[i]] = max(gap[a[i]], i - last[a[i]])
		last[a[i]] = i
	for v in range(1, n + 1):
		gap[v] = max(gap[v], n - last[v])
	INF = 10 ** 9
	candidates = [INF for i in range(n + 2)]
	for v in range(1, n + 1):
		candidates[gap[v]] = min(candidates[gap[v]], v)
	ans = INF
	for k in range(1, n + 1):
		ans = min(ans, candidates[k])
		print(-1 if ans == INF else ans, end=' ')
	print()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	(*a,) = R()
	d = {i: [-1] for i in set(a)}
	v = [-1] * n
	for i in range(n):
		d[a[i]] += (i,)
	for i in d:
		d[i] += (n,)
		df = -1
		p = d[i][0]
		for el in d[i][1:]:
			df = max(df, el - p)
			p = el
		if v[df - 1] == -1:
			v[df - 1] = i
		else:
			v[df - 1] = min(i, v[df - 1])
	flg = True
	mn = N
	for i in range(n):
		if flg:
			if v[i] > -1:
				flg = False
				mn = min(v[i], mn)
		else:
			if v[i] == -1:
				v[i] = mn
				continue
			mn = min(v[i], mn)
			v[i] = mn
	print(*v)


def solve():
	N = int(input())
	As = list(map(int, input().split()))
	last = [-1] * (N + 1)
	dist = [-1] * (N + 1)
	for (i, A) in enumerate(As):
		dist[A] = max(dist[A], i - last[A])
		last[A] = i
	for A in range(N + 1):
		dist[A] = max(dist[A], N - last[A])
	answer = [10 ** 9] * (N + 1)
	for (k, d) in enumerate(dist):
		if d > N:
			continue
		answer[d] = min(answer[d], k)
	for i in range(N):
		answer[i + 1] = min(answer[i], answer[i + 1])
	for i in range(N + 1):
		if answer[i] == 10 ** 9:
			answer[i] = -1
	print(*answer[1:])
T = int(input())
for _ in range(T):
	solve()


t = int(input())
for p in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	ind = []
	for j in range(n + 1):
		ind.append([-1])
	for j in range(n):
		ind[b[j]].append(j)
	ord = []
	j = 1
	while j <= n:
		if len(ind[j]) < 2:
			pass
		else:
			m = 0
			q = 1
			while q < len(ind[j]):
				m = max(m, ind[j][q] - ind[j][q - 1] - 1)
				q += 1
			m = max(m, n - 1 - ind[j][-1])
			ord.append([m, j])
		j += 1
	ord.sort()
	if n % 2 != 0:
		ans = []
		j = 1
		i = 0
		m = float('inf')
		while j <= n:
			while i < len(ord):
				if ord[i][0] < j:
					m = min(m, ord[i][1])
				else:
					break
				i += 1
			if m == float('inf'):
				ans.append(-1)
			else:
				ans.append(m)
			j += 1
		l = n - (n // 2 + 1)
		j = n // 2
		i = n // 2
		m = float('inf')
		while j < n and i >= 0:
			m = min(m, b[i], b[j])
			if ans[l] == -1:
				ans[l] = float('inf')
			ans[l] = min(ans[l], m)
			i += -1
			j += 1
			l += 1
	else:
		l = n // 2
		ans = []
		j = 1
		i = 0
		m = float('inf')
		while j <= n:
			while i < len(ord):
				if ord[i][0] < j:
					m = min(m, ord[i][1])
				else:
					break
				i += 1
			if m == float('inf'):
				ans.append(-1)
			else:
				ans.append(m)
			j += 1
		j = n // 2
		i = n // 2 - 1
		m = float('inf')
		while j < n and i >= 0:
			m = min(m, b[i], b[j])
			if ans[l] == -1:
				ans[l] = float('inf')
			ans[l] = min(ans[l], m)
			i += -1
			j += 1
			l += 1
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	period = [-1] * (max(arr) + 7)
	index = [-1] * (max(arr) + 7)
	for i in range(len(arr)):
		period[arr[i]] = max(period[arr[i]], i - index[arr[i]])
		index[arr[i]] = i
	for i in range(len(period)):
		period[i] = max(period[i], n - index[i])
	final = {}
	for i in range(len(period)):
		if period[i] in final:
			final[period[i]] = min(final[period[i]], i)
		else:
			final[period[i]] = i
	ans = [float('inf')] * n
	for i in range(n):
		if i + 1 in final:
			ans[i] = final[i + 1]
	curr = float('inf')
	for i in range(len(ans)):
		if ans[i] == float('inf'):
			if curr == float('inf'):
				ans[i] = -1
			else:
				ans[i] = curr
		else:
			curr = min(curr, ans[i])
			ans[i] = curr
	print(*ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ind = [[] for i in range(n + 1)]
	num = [n + 5] * (n + 2)
	for i in range(n):
		ind[arr[i]].append(i)
	for i in range(n + 1):
		mini = -1
		cur = -1
		for j in ind[i]:
			mini = max(j - cur, mini)
			cur = j
		mini = max(n - cur, mini)
		num[mini] = min(i, num[mini])
	ans = []
	for i in range(1, n + 1):
		num[i] = min(num[i], num[i - 1])
		if num[i] == n + 5:
			ans.append(-1)
		else:
			ans.append(num[i])
	print(' '.join((str(x) for x in ans)))


fullans = ''
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ar = [[] for i in range(n)]
	ans = [None] * n
	for i in range(n):
		ar[ls[i] - 1].append(i)
	for j in range(n):
		if len(ar[j]) == 0:
			continue
		mn = ar[j][0]
		for i in range(1, len(ar[j])):
			mn = max(ar[j][i] - ar[j][i - 1] - 1, mn)
		mn = max(n - 1 - ar[j][-1], mn)
		if ans[mn] is None:
			ans[mn] = j + 1
	curr = -1
	for i in range(n):
		if ans[i] is None:
			ans[i] = curr
		elif curr == -1:
			curr = ans[i]
		else:
			curr = min(ans[i], curr)
			ans[i] = curr
	for i in ans:
		print(i, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		temp = dic.get(a[i], 0)
		if temp == 0:
			dic[a[i]] = [i + 1, 0, n - i]
		else:
			dic[a[i]] = [temp[0], max(temp[1], temp[2] - (n - i)), n - i]
	lis = []
	ans = [300001] * n
	for (k, v) in dic.items():
		MAX = max(v)
		ans[MAX - 1] = min(k, ans[MAX - 1])
	if ans[0] == 300001:
		ans[0] = -1
	for i in range(1, n):
		if ans[i - 1] == -1:
			if ans[i] == 300001:
				ans[i] = -1
		else:
			ans[i] = min(ans[i - 1], ans[i])
	print(' '.join((str(n) for n in ans)))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	n = stdint()
	arr = list(stdarr())
	ind = dd(list)
	for i in range(n):
		ind[arr[i]].append(-1)
	for i in range(n):
		ind[arr[i]].append(i)
	for i in ind:
		ind[i].append(n)
	c = dd(list)
	for i in ind:
		l = ind[i]
		m = -1
		for j in range(len(l) - 1):
			d = l[j + 1] - l[j]
			m = max(d, m)
		c[m].append(i)
	res = [-1] * n
	for i in range(n):
		if len(c[i + 1]) == 0:
			if i != 0:
				res[i] = res[i - 1]
		elif res[i - 1] == -1:
			res[i] = min(c[i + 1])
		else:
			res[i] = min(res[i - 1], min(c[i + 1]))
	print(*res)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(arr):
	console('----- solving ------')
	d = defaultdict(list)
	for (i, a) in enumerate(arr):
		d[a].append(i)
	minval = {}
	for (k, v) in d.items():
		v = [-1] + v + [len(arr)]
		minval[k] = max((b - a for (a, b) in zip(v, v[1:])))
	minval2 = sorted([(v, k) for (k, v) in minval.items()])
	console(minval2)
	curmin = 10 ** 10
	res = []
	cur = 0
	for (v, k) in minval2:
		if v == cur:
			continue
		while cur < v - 1 and cur < len(arr):
			cur += 1
			res.append(curmin)
		curmin = min(curmin, k)
		cur += 1
		res.append(curmin)
	console(res)
	while cur < len(arr):
		cur += 1
		res.append(curmin)
	res = [-1 if x == 10 ** 10 else x for x in res]
	return res

def console(*args):
	return

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst)
	res = ' '.join((str(x) for x in res))
	print(res)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	dic_Previous = defaultdict(lambda : 0)
	dic_maxdis = defaultdict(lambda : 0)
	for i in l:
		dic_Previous[i] = -1
		dic_maxdis[i] = 0
	for i in range(n):
		dis = i - dic_Previous[l[i]]
		dic_maxdis[l[i]] = max(dis, dic_maxdis[l[i]])
		dic_Previous[l[i]] = i
	for i in range(n):
		dis = n - dic_Previous[l[i]]
		dic_maxdis[l[i]] = max(dis, dic_maxdis[l[i]])
	l = []
	for i in dic_maxdis.keys():
		l.append([dic_maxdis[i], i])
	l.sort()
	ans = [10000000] * (n + 1)
	for pair in l:
		ans[pair[0]] = min(ans[pair[0]], pair[1])
	f = 0
	for i in range(n + 1):
		if ans[i] != 10000000:
			break
		if f == 0:
			ans[i] = -1
	for j in range(i + 1, n + 1):
		ans[j] = min(ans[j], ans[j - 1])
	print(*ans[1:])


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		if arr[i] in d:
			d[arr[i]].append(i + 1)
		else:
			d[arr[i]] = [i + 1]
	d = sorted(d.items(), key=lambda x: x[0])
	ans = [-1] * (n + 1)
	for i in d:
		last = 0
		maxx = 0
		for j in i[1]:
			maxx = max(maxx, j - last)
			last = j
		ii = max(maxx, n - last + 1)
		while ii <= n and ans[ii] == -1:
			ans[ii] = i[0]
			ii += 1
	print(*ans[1:])


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))
test_cases = inp()
max_poss = 3123456

def solve():
	n = inp()
	arr = inlt()
	max_dist = {}
	last_ind = {}
	for (ind, num) in enumerate(arr):
		dist = ind - last_ind.get(num, -1)
		if num not in max_dist:
			max_dist[num] = dist
		else:
			max_dist[num] = max(max_dist[num], dist)
		last_ind[num] = ind
	for (num, last_index) in last_ind.items():
		dist = n - last_index
		max_dist[num] = max(max_dist[num], dist)
	answers_rev = {}
	for (num, dist) in max_dist.items():
		if dist not in answers_rev:
			answers_rev[dist] = num
		else:
			answers_rev[dist] = min(answers_rev[dist], num)
	ans = ''
	min_number_found = None
	for i in range(1, n + 1):
		answer = answers_rev.get(i, max_poss)
		if answer != max_poss:
			if min_number_found is None:
				min_number_found = answer
			if answer < min_number_found:
				min_number_found = answer
		if min_number_found is not None:
			ans += '{}'.format(min_number_found)
		else:
			ans += '-1'.format(min_number_found)
		if i < n:
			ans += ' '
		else:
			ans += '\n'
	print(ans)
for test in range(test_cases):
	solve()


import os, sys
from io import BytesIO, IOBase
from collections import defaultdict

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		ind = defaultdict(list)
		for (i, val) in enumerate(arr):
			ind[val].append(i)
		ans = [10 ** 10] * n
		for i in ind:
			maxi = ind[i][0] + 1
			for x in range(len(ind[i]) - 1):
				maxi = max(maxi, ind[i][x + 1] - ind[i][x])
			maxi = max(maxi, n - ind[i][-1])
			ans[maxi - 1] = min(ans[maxi - 1], i)
		mini = 10 ** 10
		for (i, val) in enumerate(ans):
			mini = min(mini, val)
			ans[i] = mini
		for (i, val) in enumerate(ans):
			if val == 10 ** 10:
				ans[i] = -1
		print(' '.join(map(str, ans)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		block = [(0, 0, 0)] * (n + 1)
		for i in range(n):
			(x, y, z) = block[a[i]]
			if y == 0:
				x = i + 1
			else:
				x = max(x, i + 1 - y)
			y = i + 1
			z = i + 1
			block[a[i]] = (x, y, z)
		ans = [-1] * (n + 1)
		for x in range(1, n + 1):
			m = max(block[x][0], n - block[x][2] + 1)
			if not m:
				continue
			for i in range(m, n + 1):
				if ans[i] == -1:
					ans[i] = x
				else:
					break
		print(*ans[1:])
main()


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
from time import time
start = time()
t = 1000
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	last = defaultdict(lambda : -1)
	d = Counter()
	for (i, a) in enumerate(arr):
		tmp = i - last[a]
		last[a] = i
		d[a] = max(d[a], tmp)
	for a in last:
		d[a] = max(d[a], n - last[a])
	ans = [inf] * n
	for a in d:
		ans[d[a] - 1] = min(ans[d[a] - 1], a)
	for j in range(1, n):
		ans[j] = min(ans[j - 1], ans[j])
	for j in range(n):
		if ans[j] == inf:
			ans[j] = -1
	ans = map(str, ans)
	print(' '.join(ans))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	hd = [-1] * (n + 1)
	maxhd = [0] * (n + 1)
	for i in range(n):
		if i - hd[a[i]] > maxhd[a[i]]:
			maxhd[a[i]] = i - hd[a[i]]
		hd[a[i]] = i
	for i in range(1, n + 1):
		if n - hd[i] > maxhd[i]:
			maxhd[i] = n - hd[i]
	ans = [-1] * (n + 1)
	k = n + 1
	for i in range(1, n + 1):
		if maxhd[i] == n + 1:
			continue
		for j in range(maxhd[i], k):
			ans[j] = i
		k = min(k, maxhd[i])
	print(*ans[1:])


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		locs = [[-1] for u in range(n + 1)]
		for i in range(n):
			locs[a[i]].append(i)
		for i in range(1, n + 1):
			locs[i].append(n)
		b = []
		for i in range(1, n + 1):
			if len(locs[i]) > 1:
				gap = 0
				for j in range(1, len(locs[i])):
					gap = max(gap, locs[i][j] - locs[i][j - 1])
				b.append([gap, i])
		b.sort()
		idx = 0
		mn = 10 ** 9
		output = [0] * n
		for k in range(1, n + 1):
			while idx < len(b) and k >= b[idx][0]:
				mn = min(mn, b[idx][1])
				idx += 1
			if idx == 0:
				output[k - 1] = -1
			else:
				output[k - 1] = mn
		print(*output)
prog()


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	setA = set(A)
	if len(setA) == 1:
		print(*[A[0]] * n)
		continue
	last_pos = [-1] * (n + 1)
	max_dis = [0] * (n + 1)
	for (i, a) in enumerate(A):
		max_dis[a] = max(max_dis[a], i - last_pos[a])
		last_pos[a] = i
	for a in list(setA):
		max_dis[a] = max(max_dis[a], n - last_pos[a])
	res = [-1] * n
	for (i, dis) in enumerate(max_dis):
		if dis == 0:
			continue
		elif res[dis - 1] == -1:
			res[dis - 1] = i
	for i in range(n - 1):
		if res[i] != -1:
			if res[i + 1] > res[i] or res[i + 1] == -1:
				res[i + 1] = res[i]
	print(*res)


def ind(lst, m):
	result = []
	for ab in range(m):
		result.append([-1])
	for z in range(m):
		result[lst[z] - 1].append(z)
	for ab in range(m):
		result[ab].append(m)
	return result
t = int(input())
for i in range(t):
	n = int(input())
	ans = [-1] * n
	a = [int(x) for x in input().split()]
	s = set(a)
	te = ind(a, n)
	for j in s:
		maxx = -1
		for k in range(len(te[j - 1]) - 1):
			maxx = max(maxx, te[j - 1][k + 1] - te[j - 1][k])
		for k in range(maxx - 1, n):
			if ans[k] != -1:
				if ans[k] > j:
					ans[k] = j
				else:
					break
			else:
				ans[k] = j
	print(*ans)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		ans = [-1] * n
		d = defaultdict(set)
		temp = defaultdict(list)
		for i in range(n):
			d[ar[i]].add(i)
			temp[ar[i]].append(i)
		tp = list(set(ar))
		tp.sort()
		gl = 10 ** 9
		for i in tp:
			temp[i].insert(0, -1)
			temp[i].append(n)
			mn = 0
			for j in range(len(temp[i]) - 1):
				mn = max(mn, abs(temp[i][j] - temp[i][j + 1]))
			if gl > mn:
				gl = mn
				ans[mn - 1] = i
		v = -1
		for i in range(n):
			if ans[i] != -1:
				v = ans[i]
			ans[i] = v
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for qq in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	last = [-1] * (n + 1)
	dura = [-1] * (n + 1)
	for i in range(n):
		dura[a[i]] = max(dura[a[i]], i - last[a[i]] - 1)
		last[a[i]] = i
	for i in range(n + 1):
		dura[i] = max(dura[i], n - last[i] - 1)
	ans = [n + 1] * n
	for i in range(n + 1):
		if dura[i] == n:
			continue
		ans[dura[i]] = min(ans[dura[i]], i)
	for i in range(n - 1):
		ans[i + 1] = min(ans[i + 1], ans[i])
	for i in range(n):
		if ans[i] == n + 1:
			ans[i] = -1
	print(*ans)


def Work():
	global n, arr, f, last, ans
	n = int(input())
	arr = [0] * (n + 1)
	arr[1:] = list(map(int, input().split()))
	f = [0] * (n + 1)
	ans = [-1] * (n + 1)
	last = [0] * (n + 1)
	for i in range(1, n + 1):
		f[arr[i]] = max(f[arr[i]], i - last[arr[i]])
		last[arr[i]] = i
	for x in range(1, n + 1):
		f[x] = max(f[x], n - last[x] + 1)
		i = f[x]
		while i <= n and ans[i] == -1:
			ans[i] = x
			i += 1
	for e in range(1, n + 1):
		print(ans[e], end=' ')
	print()
t = int(input())
for _ in range(t):
	Work()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = [-1] * (n + 1)
	b = [[] for i in range(n + 1)]
	for i in range(n):
		b[a[i]].append(i + 1)
	p = n
	for i in range(1, n + 1):
		if b[i] == []:
			continue
		m = 0
		m = b[i][0]
		for j in range(1, len(b[i])):
			m = max(b[i][j] - b[i][j - 1], m)
		m = max(m, n + 1 - b[i][-1])
		if m > p:
			continue
		for k in range(m, p + 1):
			res[k] = i
		p = m - 1
	print(*res[1:])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	di = {}
	di2 = {}
	for i in range(n):
		if a[i] not in di:
			di[a[i]] = -1
			di2[a[i]] = 0
		di2[a[i]] = max(di2[a[i]], i - di[a[i]])
		di[a[i]] = i
	ans = [-1] * len(a)
	looking_for_less_than = n + 1
	for i in di2:
		di2[i] = max(di2[i], n - di[i])
	for each in sorted((k for k in di)):
		if di2[each] >= looking_for_less_than:
			continue
		for i in range(di2[each] - 1, looking_for_less_than - 1):
			ans[i] = each
		looking_for_less_than = di2[each]
	print(*ans)


from bisect import bisect_left, bisect_right
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque, defaultdict
import math
import heapq
import re

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
LOW = 'abcdefghijklmnopqrstuvwxyz'
UP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def main():
	for _ in range(iin()):
		n = iin()
		a = ain()
		d = {}
		for i in range(n):
			d[a[i]] = [-1, MIN]
		l = [-1] * n
		for i in range(n):
			d[a[i]][1] = max(d[a[i]][1], i - d[a[i]][0])
			d[a[i]][0] = i
		for key in d.keys():
			d[key][1] = max(d[key][1], n - d[key][0])
			maxi = d[key][1]
			if l[maxi - 1] == -1:
				l[maxi - 1] = key
			else:
				l[maxi - 1] = min(l[maxi - 1], key)
		temp = -1
		for i in range(n):
			if l[i] != -1:
				if temp == -1:
					temp = l[i]
				else:
					temp = min(temp, l[i])
					l[i] = temp
			else:
				l[i] = temp
		print(*l)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
outputs = []
t = int(stdin.readline().strip())
for __ in range(t):
	n = int(stdin.readline().strip())
	res = [n + 2] * n
	arr = [int(num) for num in stdin.readline().strip().split()]
	req = [[-1, -1, -1] for i in range(n + 1)]
	for i in range(n):
		if req[arr[i]][0] == -1:
			req[arr[i]][0] = i
			req[arr[i]][1] = max(i + 1, n - i)
			req[arr[i]][2] = 1
		elif req[arr[i]][2] == 1:
			req[arr[i]][2] += 1
			req[arr[i]][1] = max(req[arr[i]][0] + 1, i - req[arr[i]][0])
			req[arr[i]][0] = i
		else:
			req[arr[i]][2] += 1
			req[arr[i]][1] = max(req[arr[i]][1], i - req[arr[i]][0])
			req[arr[i]][0] = i
	for i in range(n):
		if req[arr[i]][2] > 1:
			req[arr[i]][1] = max(req[arr[i]][1], n - req[arr[i]][0])
	for i in range(n):
		res[req[arr[i]][1] - 1] = min(arr[i], res[req[arr[i]][1] - 1])
	i = 0
	while i < n and res[i] == n + 2:
		res[i] = '-1'
		i += 1
	cur_minm = -1 if i > n else res[i]
	while i < n:
		cur_minm = min(cur_minm, res[i])
		res[i] = f'{cur_minm}'
		i += 1
	outputs.append(' '.join(res))
for output in outputs:
	stdout.write(output + '\n')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	_A = sorted(set(a))
	ind = defaultdict(lambda : [0])
	for i in range(n):
		ind[a[i]].append(i + 1)
	for i in ind:
		ind[i].append(n + 1)
	ans = [inf] * (n + 1)
	for i in _A:
		ma = 1
		for j in range(1, len(ind[i])):
			ma = max(ind[i][j] - ind[i][j - 1], ma)
		ans[ma] = min(i, ans[ma])
	ans = ans[1:]
	last = inf
	for i in range(len(ans)):
		ans[i] = min(last, ans[i])
		last = ans[i]
		if last == inf:
			ans[i] = -1
	print(*ans)


gans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	d = dict()
	w = []
	v = []
	ind = 0
	for i in range(n):
		if u[i] not in d.keys():
			d[u[i]] = ind
			w.append([])
			w[ind].append(i)
			ind += 1
			v.append(u[i])
		else:
			w[d[u[i]]].append(i)
	m = ind
	vans = [0] * m
	for i in range(m):
		mx = max(w[i][0] + 1, n - w[i][-1])
		for j in range(1, len(w[i])):
			mx = max(w[i][j] - w[i][j - 1], mx)
		vans[i] = (mx, -v[i])
	vans.sort()
	ans = [0] * n
	vv = [-1] * n
	ind = 0
	for i in range(n):
		if vans[ind][0] > i + 1:
			continue
		while ind + 1 < len(vans) and vans[ind + 1][0] <= i + 1:
			ind += 1
		vv[i] = -vans[ind][1]
		if i > 0 and vv[i - 1] != -1:
			vv[i] = min(vv[i], vv[i - 1])
	gans.append(' '.join(map(str, vv)))
print('\n'.join(gans))


from sys import stdin
t = int(stdin.readline())
for case in range(t):
	n = int(stdin.readline())
	array = list(map(int, stdin.readline().split()))
	dict1 = {}
	dict2 = {}
	ans = [-1] * n
	for i in range(n):
		if array[i] not in dict2:
			dict2[array[i]] = i
			dict1[array[i]] = i
		else:
			dict2[array[i]] = max(dict2[array[i]], i - dict1[array[i]] - 1)
			dict1[array[i]] = i
	for i in dict2:
		dict2[i] = max(dict2[i], n - dict1[i] - 1)
	sorts = sorted(list(dict2.keys()))
	for i in sorts:
		for j in range(dict2[i], n):
			if ans[j] != -1:
				break
			else:
				ans[j] = i
	print(' '.join([str(i) for i in ans]))


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline()

def mpint():
	return map(int, sys.stdin.readline().split(' '))

def itg():
	return int(sys.stdin.readline())
INF = int(1000000.0)

def solve():
	n = itg()
	arr = tuple(mpint())
	index_dict = {}
	max_dis = {}
	for a in arr:
		index_dict[a] = -1
		max_dis[a] = -INF
	for (i, a) in enumerate(arr):
		max_dis[a] = max(max_dis[a], i - index_dict[a])
		index_dict[a] = i
	for key in max_dis:
		max_dis[key] = max(max_dis[key], n - index_dict[key])
	ans = [-1] * n
	for key in sorted(max_dis, reverse=True):
		dis = max_dis[key]
		ans[dis - 1] = key
	for i in range(n - 1):
		if ans[i] == -1:
			continue
		if ans[i + 1] == -1 or ans[i + 1] > ans[i]:
			ans[i + 1] = ans[i]
	return ans
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
for _ in range(itg()):
	print(*solve())


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [n + 1] * (n + 2)
	index = defaultdict(lambda : [0])
	for i in range(n):
		index[arr[i]].append(i + 1)
	for key in index.keys():
		index[key].append(n + 1)
	for (key, indices) in index.items():
		maximumGap = -1
		length = len(indices)
		for i in range(1, length):
			val = indices[i] - indices[i - 1]
			maximumGap = max(maximumGap, val)
		ans[maximumGap] = min(ans[maximumGap], key)
	for i in range(1, n + 1):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(1, n + 1):
		if ans[i] == n + 1:
			print(-1, end=' ')
		else:
			print(ans[i], end=' ')
	print()


def dif_maker(q):
	x = []
	for i in range(len(q) - 1):
		x.append(q[i + 1] - q[i])
	return max(x)
for ad in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [-1] * n
	y = []
	for i in range(n + 1):
		y.append([-1])
	for i in range(n):
		y[l[i]].append(i)
	for i in range(n + 1):
		y[i].append(n)
	a = []
	for i in y:
		a.append(dif_maker(i))
	c = n + 1
	z = []
	for i in range(n + 1):
		x = a[i]
		if c > x:
			z += [i] * (c - x)
			c = x
	ans = z + [-1] * (n - len(z))
	ans.reverse()
	for i in ans:
		print(i, end=' ')
	print()


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = sorted(list(map(int, input().split())))
		tot = 0
		for i in range(1, n):
			tot += (k - a[i]) // a[0]
		print(tot)

def B():
	from collections import defaultdict
	t = int(input())
	for _ in range(t):
		(n, T) = map(int, input().split())
		a = list(map(int, input().split()))
		d = defaultdict()
		colors = [0] * n
		for i in range(n):
			colors[i] = d.get(a[i], 0)
			d[T - a[i]] = (1 + colors[i]) % 2
		print(*colors)

def C():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		nums = [[] for i in range(n + 1)]
		for i in range(n):
			nums[a[i]].append(i)
		s = [300001] * (n + 1)
		for i in range(len(nums)):
			if len(nums[i]) > 0:
				maxdist = max(nums[i][0] + 1, n - nums[i][-1])
				for j in range(1, len(nums[i])):
					maxdist = max(maxdist, nums[i][j] - nums[i][j - 1])
				s[maxdist] = min(s[maxdist], i)
		ans = [s[1]] * n
		for i in range(1, n):
			ans[i] = min(ans[i - 1], s[i + 1])
		for i in range(n):
			if ans[i] == 300001:
				ans[i] = -1
		print(*ans)
C()


def main(inp):
	t = int(inp())
	for __ in range(t):
		n = int(inp())
		arr = split_inp_int(inp)
		last_occur = [-1] * (n + 1)
		max_dist = [0] * (n + 1)
		for (i, a) in enumerate(arr):
			max_dist[a] = max(max_dist[a], i - last_occur[a])
			last_occur[a] = i
		for a in range(1, n + 1):
			max_dist[a] = max(max_dist[a], n - last_occur[a])
		max_dist_pair = [(i + 1, min_k) for (i, min_k) in enumerate(max_dist[1:])]
		max_dist_pair.sort(reverse=True)
		ans = []
		for k in range(n, 0, -1):
			while max_dist_pair and max_dist_pair[-1][1] > k:
				max_dist_pair.pop()
			if len(max_dist_pair) == 0:
				ans.append(-1)
				continue
			ans.append(max_dist_pair[-1][0])
		print(' '.join(map(str, ans[::-1])))

def split_inp_int(inp):
	return list(map(int, inp().split()))

def use_fast_io():
	import sys

	class InputStorage:

		def __init__(self, lines):
			lines.reverse()
			self.lines = lines

		def input_func(self):
			if self.lines:
				return self.lines.pop()
			else:
				return ''
	input_storage_obj = InputStorage(sys.stdin.readlines())
	return input_storage_obj.input_func
from collections import Counter, defaultdict
from functools import reduce
import operator
import math

def product(arr_):
	return reduce(operator.mul, arr_, 1)
main(use_fast_io())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		x = a[i]
		if not x in d:
			d[x] = (i, i + 1)
		else:
			(j, r) = d[x]
			d[x] = (i, max(i - j, r))
	nl = []
	for x in d.keys():
		(i, r) = d[x]
		nl.append((max(r, n - i), x))
	nl.sort()
	nl += [(float('inf'), float('inf'))]
	h = {}
	r = nl[0][0]
	i = 0
	kmin = nl[0][1]
	for v in range(r, n + 1):
		while nl[i][0] <= v:
			kmin = min(kmin, nl[i][1])
			i += 1
		h[v] = kmin
	for i in range(1, nl[0][0]):
		print(-1, end=' ')
	for i in h.keys():
		print(h[i], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [10 ** 6] * n
	mn = dict()
	for i in range(n):
		if a[i] in mn:
			mn[a[i]].append(i)
		else:
			mn[a[i]] = [i, -1, n]
	for i in mn:
		c = 0
		mn[i].sort()
		for j in range(1, len(mn[i])):
			c = max(c, mn[i][j] - mn[i][j - 1] - 1)
		b[c] = min(b[c], i)
	b[-1] = min(a)
	for i in range(1, n):
		b[i] = min(b[i], b[i - 1])
	for i in range(n):
		if b[i] == 10 ** 6:
			b[i] = -1
	print(*b)


import math

def get_int():
	return int(input())

def get_ints():
	return [int(i) for i in input().split()]
for t in range(0, get_int()):
	n = get_int()
	nums = get_ints()
	hist = {}
	for i in range(0, n):
		e = nums[i]
		if e in hist:
			hist[e].append(i)
		else:
			hist[e] = [i]
	results = [-1] * n
	filled = n + 1
	for e in sorted(hist):
		gap = -1
		last_idx = -1
		for x in hist[e]:
			gap = max(gap, x - last_idx)
			last_idx = x
		gap = max(gap, n - hist[e][-1])
		tmp = gap
		while gap < filled:
			results[gap - 1] = e
			gap += 1
		filled = min(tmp, filled)
	print(*results, sep=' ')


import sys
input = sys.stdin.readline
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = sorted(a)
	dict = {}
	for (i, x) in enumerate(a):
		if x in dict.keys():
			dict[x] += [i]
		else:
			dict[x] = [i]
	c = [[k, [-1] + v + [n]] for (k, v) in dict.items()]
	c.sort(key=lambda x: x[0])
	d = []
	for y in c:
		m = 1
		for i in range(1, len(y[1])):
			m = max(y[1][i] - y[1][i - 1], m)
		d.append([y[0], m])
	ans = []
	j = n
	for item in d:
		ans.extend([item[0]] * max(0, j - item[1] + 1))
		if item[1] <= j:
			j = item[1] - 1
	ans += [-1] * (n - len(ans))
	print(*ans[::-1])


import sys
z = sys.stdin.readline
for _ in range(int(z())):
	n = int(z())
	a = [*map(int, z().split())]
	f = [0] * n
	l = [-1] * n
	for i in range(n):
		v = a[i] - 1
		f[v] = max(f[v], i - l[v])
		l[v] = i
	for i in range(n):
		f[i] = max(f[i], n - l[i])
	g = sorted(zip(f, range(n)))
	o = []
	p = 0
	m = -2
	for i in range(1, n + 1):
		while i > g[p][0]:
			p += 1
		if i == g[p][0] and (m < 0 or g[p][1] < m):
			m = g[p][1]
		o.append(m + 1)
	print(' '.join(map(str, o)))


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def input_int():
	return int(input())

def input_int_list():
	return list(map(int, input().split()))

def print_int_list(l):
	cout << ' '.join(map(str, l)) << endl

def solve():
	t = int(input())
	for _ in range(t):
		n = input_int()
		arr = input_int_list()
		mx_k_vals = [0] * (n + 1)
		prev = [0] * (n + 1)
		res = [-1] * (n + 1)
		for i in range(1, n + 1):
			ele = arr[i - 1]
			mx_k_vals[ele] = max(mx_k_vals[ele], i - prev[ele])
			prev[ele] = i
		for i in range(1, n + 1):
			mx_k_vals[i] = max(mx_k_vals[i], n - prev[i] + 1)
			for k_val in range(mx_k_vals[i], n + 1):
				if res[k_val] != -1:
					break
				res[k_val] = i
		print_int_list(res[1:])

def main():
	solve()
main()


def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	distmp = {}
	lastidx = {}
	inf = n * 10
	ans = [inf] + [inf] * n
	for i in range(n):
		if arr[i] in lastidx:
			distmp[arr[i]] = max(distmp[arr[i]], i - lastidx[arr[i]])
		else:
			distmp[arr[i]] = i + 1
		lastidx[arr[i]] = i
	for k in lastidx.keys():
		distmp[k] = max(distmp[k], n - lastidx[k])
	for i in range(1, n + 1):
		if i in distmp:
			ans[distmp[i]] = min(i, ans[distmp[i]])
	for i in range(1, n + 1):
		ans[i] = min(ans[i - 1], ans[i])
	for i in range(n + 1):
		if ans[i] == inf:
			ans[i] = -1
	print(*ans[1:])
t = int(input())
for _ in range(t):
	solve()


import array

def readis():
	return map(int, input().strip().split())
T = int(input())

def best_k(idxs_sorted, n):
	best = -1
	last = -1
	for idx in idxs_sorted:
		best = max(best, idx - last)
		last = idx
	return max(best, n - last)
while T:
	T -= 1
	n = int(input())
	d = {x: [] for x in range(n + 1)}
	for (idx, x) in enumerate(readis()):
		d[x].append(idx)
	d = {x: best_k(idxs, n) for (x, idxs) in d.items() if idxs}
	ans = array.array('i', (-1 for _ in range(n)))
	for (x, best) in d.items():
		idx = best - 1
		while idx < n and ans[idx] == -1:
			ans[idx] = x
			idx += 1
	print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(len(l)):
		x = l[i]
		if x in d:
			d[x].append(i + 1)
		else:
			d[x] = [0]
			d[x].append(i + 1)
	ans = [10 ** 18 for i in range(n + 1)]
	for x in d:
		p = d[x]
		cnt = 0
		for i in range(len(p)):
			if i == len(p) - 1:
				cnt = max(cnt, n - p[i] + 1)
			else:
				cnt = max(cnt, p[i + 1] - p[i])
		if cnt < n + 1:
			ans[cnt] = min(ans[cnt], x)
	m = 10 ** 18
	for i in range(1, len(ans)):
		m = min(m, ans[i])
		ans[i] = m
		if m == 10 ** 18:
			ans[i] = -1
	print(*ans[1:])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ind = [[0] for i in range(n + 1)]
	maxi = int(100000000.0)
	ans = [maxi] * (n + 1)
	for i in range(n):
		ind[a[i]].append(i + 1)
	for i in range(n + 1):
		ind[i].append(n + 1)
	for i in range(1, n + 1):
		(pre, m) = (0, 0)
		for j in range(1, len(ind[i])):
			m = max(m, ind[i][j] - pre)
			pre = ind[i][j]
		if m < n + 1:
			ans[m] = min(ans[m], i)
	val = ans[1]
	for i in range(1, n + 1):
		ans[i] = min(val, ans[i])
		val = ans[i]
		if ans[i] == maxi:
			ans[i] = -1
	print(*ans[1:])


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
import operator
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = inar()
		dic = defaultdict(list)
		for i in range(n):
			dic[arr[i]].append(i)
		dic = dict(sorted(dic.items(), key=operator.itemgetter(0)))
		res = [-1] * n
		for (key, item) in dic.items():
			mx = 0
			mx = max(mx, item[0] + 1)
			mx = max(mx, n - item[-1])
			for j in range(len(item)):
				mx = max(mx, item[j] - item[j - 1])
			if res[mx - 1] == -1:
				res[mx - 1] = key
				temp = mx
				while temp < n and res[temp] == -1:
					res[temp] = key
					temp += 1
		print(*res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for testcase in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	for i in range(len(a)):
		a[i] -= 1
	last = [-1] * n
	maxdist = [-1] * n
	for i in range(len(a)):
		maxdist[a[i]] = max(i - last[a[i]] - 1, maxdist[a[i]])
		last[a[i]] = i
	for i in range(len(maxdist)):
		maxdist[i] = max(n - last[i] - 1, maxdist[i])
	x = n + 1
	y = 0
	for i in range(len(maxdist)):
		if x > maxdist[i]:
			x = maxdist[i]
			y = i
	ans = [n] * n
	for i in range(len(maxdist)):
		if maxdist[i] != n:
			ans[maxdist[i]] = min(ans[maxdist[i]], i + 1)
	minans = n + 1
	for i in range(len(ans)):
		minans = min(minans, ans[i])
		ans[i] = minans
	for i in range(len(ans)):
		if ans[i] == n and (not (y == n - 1 and i >= maxdist[-1])):
			ans[i] = -1
	print(' '.join(list(map(str, ans))))


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			n = int(R())
			a = [0] + [int(x) for x in R().split()]
			tmp_max_gap = {}
			for j in range(1, n + 1):
				if a[j] not in tmp_max_gap:
					tmp_max_gap[a[j]] = [j, j]
				else:
					tmp_max_gap[a[j]][0] = max(tmp_max_gap[a[j]][0], j - tmp_max_gap[a[j]][1])
					tmp_max_gap[a[j]][1] = j
			max_gap = []
			for j in tmp_max_gap:
				max_gap.append((j, max(tmp_max_gap[j][0], n + 1 - tmp_max_gap[j][1])))
			max_gap.sort(key=lambda x: x[0])
			color = ['-1' for j in range(n + 1)]
			pos = n + 1
			for j in range(len(max_gap)):
				if max_gap[j][1] < pos:
					color[max_gap[j][1]] = str(max_gap[j][0])
					pos = max_gap[j][1]
			val = '-1'
			for j in range(1, n + 1):
				if color[j] != val and color[j] != '-1':
					val = color[j]
				color[j] = str(val)
			ans.append(' '.join(color[1:]))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


from sys import stdin
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split()))
	f = [0] * (n + 1)
	last = [-1] * (n + 1)
	ans = [-1] * (n + 1)
	for i in range(0, n):
		x = a[i]
		f[x] = max(f[x], i - last[x])
		last[a[i]] = i
	for x in range(1, n + 1):
		f[x] = max(f[x], n - last[x])
		for j in range(f[x], n + 1):
			if ans[j] != -1:
				break
			ans[j] = x
	print(' '.join(map(str, ans[1:n + 1])))


from collections import defaultdict
T = int(input())
ans_ls = [0] * T
for t in range(T):
	N = int(input())
	a_ls = list(map(int, input().split()))
	a_maxdist = defaultdict(lambda : 0)
	a_last_left = defaultdict(lambda : -1)
	k_amz = [float('inf')] * N
	for i in range(N):
		now_value = a_ls[i]
		dist = i - a_last_left[now_value]
		a_maxdist[now_value] = max(a_maxdist[now_value], dist)
		a_last_left[now_value] = i
	a_last_right = defaultdict(lambda : N)
	for i in range(N - 1, -1, -1):
		now_value = a_ls[i]
		dist = a_last_right[now_value] - i
		a_maxdist[now_value] = max(a_maxdist[now_value], dist)
		a_last_right[now_value] = i
	maxdist_min = defaultdict(lambda : float('inf'))
	for (v, maxdist) in a_maxdist.items():
		maxdist_min[maxdist] = min(maxdist_min[maxdist], v)
	now_min = float('inf')
	for i in range(1, N + 1):
		now_min = min(now_min, maxdist_min[i])
		k_amz[i - 1] = now_min
	for i in range(N):
		if k_amz[i] == float('inf'):
			k_amz[i] = -1
	ans_ls[t] = k_amz
for ans in ans_ls:
	print(*ans)


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
pr = print
inf = float('inf')
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	a = inar()
	last = [-1 for i in range(n + 1)]
	gap = [-1 for i in range(n + 1)]
	for (inde, i) in enumerate(a):
		gap[i] = max(gap[i], inde - last[i])
		last[i] = inde
	for i in a:
		gap[i] = max(gap[i], n - last[i])
	gapmin = [inf for i in range(n + 1)]
	for i in range(1, n + 1):
		if gap[i] == -1:
			continue
		gapmin[gap[i]] = min(gapmin[gap[i]], i)
	ans = [inf for i in range(n + 1)]
	for i in range(1, n + 1):
		ans[i] = min(ans[i - 1], gapmin[i])
	for i in range(n + 1):
		if ans[i] == inf:
			ans[i] = -1
	pr(*ans[1:])


from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	d = {i: [] for i in range(1, n + 1)}
	for i in range(n):
		d[a[i]].append(i)
	vis = [-1] * n
	for i in range(1, n + 1):
		if len(d[i]) == 0:
			continue
		ma = -1
		for j in range(len(d[i]) - 1):
			ma = max(d[i][j + 1] - d[i][j], ma)
		if len(d[i]):
			ma = max(ma, d[i][0] - 0 + 1)
			ma = max(ma, n - d[i][-1])
		if vis[ma - 1] == -1:
			for j in range(ma - 1, n):
				if vis[j] != -1:
					break
				vis[j] = i
	print(*vis)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = [0] + arr
	d = dict()
	dp = [0] * (n + 1)
	dp1 = [0] * (n + 1)
	ans = [-1] * (n + 1)
	for j in range(1, n + 1):
		i = arr[j]
		dp[i] = max(dp[i], j - dp1[i])
		dp1[i] = j
	for x in range(1, n + 1):
		dp[x] = max(dp[x], n - dp1[x] + 1)
		i = dp[x]
		while i <= n and ans[i] == -1:
			ans[i] = x
			i += 1
	print(*ans[1:])


from collections import defaultdict
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	num2idx = defaultdict(list)
	for (i, num) in enumerate(R()):
		num2idx[num].append(i)
	res = [3 * 10 ** 6] * (n + 1)
	for (num, idxes) in num2idx.items():
		mgap = max(idxes[0] + 1, n - idxes[-1], *(i2 - i1 for (i1, i2) in zip(idxes, idxes[1:])))
		res[mgap] = min(res[mgap], num)
	cmin = res[0]
	for i in range(1, n + 1):
		cmin = min(cmin, res[i])
		print(cmin if cmin <= 3 * 10 ** 5 else -1, end=' ')
	print()


import os
import sys
import io
import functools
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
GANS = []

def cmp(x, y):
	if x[1] == y[1]:
		return y[0] - x[0]
	return x[1] - y[1]
t = int(input())
for _ in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	ctr = {}
	for i in li:
		ctr[i] = ctr.get(i, 0) + 1
	c2 = {}
	prv = {}
	d = {}
	for (p, i) in enumerate(li):
		c2[i] = c2.get(i, 0) + 1
		if i not in d:
			d[i] = p
		else:
			d[i] = max(p - prv.get(i, 0), d[i])
		if c2[i] == ctr[i]:
			d[i] = max(n - p - 1, d[i])
		prv[i] = p + 1
	srt = sorted(d.items(), key=functools.cmp_to_key(cmp))
	p = -1
	cur = 11451141919810
	for k in range(n):
		while p < len(srt) - 1 and srt[p + 1][1] <= k:
			p += 1
			cur = min(srt[p][0], cur)
		if cur == 11451141919810:
			print(-1, end=' ')
		else:
			print(cur, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	di = dict()
	di2 = dict()
	for i in range(n):
		if arr[i] not in di:
			di2[arr[i]] = 0
			di[arr[i]] = -1
		di2[arr[i]] = max(di2[arr[i]], i - di[arr[i]])
		di[arr[i]] = i
	for i in range(n):
		di2[arr[i]] = max(di2[arr[i]], n - di[arr[i]])
	ans = [-1 for _ in range(n)]
	lflt = n + 1
	for each in sorted((k for k in di)):
		if di2[each] >= lflt:
			continue
		for i in range(di2[each] - 1, lflt - 1):
			ans[i] = each
		lflt = di2[each]
	print(*ans)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	d = [[] for i in range(n + 1)]
	d2 = [0] * (n + 1)
	dp = [0] * (n + 1)
	for i in range(n):
		if d2[a[i]] == 0:
			d2[a[i]] = 1
			d[a[i]].append(i)
			dp[a[i]] = i + 1
		else:
			d2[a[i]] += 1
			dp[a[i]] = max(dp[a[i]], i - d[a[i]][-1])
			d[a[i]].append(i)
	for i in range(n):
		dp[a[i]] = max(dp[a[i]], n - d[a[i]][-1])
	ans = [-1] * (n + 1)
	temp = -1
	for i in range(n + 1):
		if ans[dp[i]] == -1:
			ans[dp[i]] = i
	temp = -1
	for i in range(1, n + 1):
		if ans[i] != -1:
			if temp == -1:
				temp = ans[i]
			elif ans[i] < temp:
				temp = ans[i]
			else:
				ans[i] = temp
		else:
			ans[i] = temp
	print(*ans[1:])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for j in range(n):
		if l[j] not in d:
			d[l[j]] = [j]
		else:
			d[l[j]].append(j)
	d1 = {}
	for j in d:
		d[j].sort()
		m = d[j][0] + 1
		for k in range(1, len(d[j])):
			m = max(m, d[j][k] - d[j][k - 1])
		m = max(m, n - d[j][len(d[j]) - 1])
		if m not in d1:
			d1[m] = j
		else:
			d1[m] = min(d1[m], j)
	l1 = [-1] * n
	m = min(list(d1))
	l1[m - 1] = d1[m]
	for j in range(m + 1, n + 1):
		if j in d1:
			l1[j - 1] = min(d1[j], l1[j - 2])
		else:
			l1[j - 1] = l1[j - 2]
	print(*l1)


import bisect
import array
import functools
import math
T = int(input())
for Tid in range(T):
	n = int(input())
	a = array.array('i', map(int, input().split()))
	b = array.array('i', [0 for i in range(n + 2)])
	la = array.array('i', [-1 for i in range(n + 2)])
	for i in range(n):
		b[a[i]] = max(b[a[i]], i - la[a[i]])
		la[a[i]] = i
	for i in range(1, n + 1):
		b[i] = max(b[i], n - la[i])
	ans = array.array('i', [1 << 30 for i in range(n + 2)])
	for i in range(1, n + 1):
		ans[b[i]] = min(ans[b[i]], i)
	for i in range(1, n + 1):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(1, n + 1):
		if ans[i] == 1 << 30:
			ans[i] = -1
		print(ans[i], end=' ')
	print()


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	big = [0] * n
	cur = [-1] * n
	ans = [-1] * (n + 1)
	for i in range(n):
		a[i] -= 1
		big[a[i]] = max(big[a[i]], i - cur[a[i]])
		cur[a[i]] = i
	for i in range(n):
		big[i] = max(big[i], n - cur[i])
	j = n
	for i in range(n):
		while j >= big[i]:
			ans[j] = i + 1
			j -= 1
	for i in range(1, n + 1):
		print(ans[i], end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())]
	f = [0] * n
	cur = [-1] * n
	d = [list() for i in range(n + 1)]
	for i in range(n):
		v = l[i] - 1
		f[v] = max(f[v], i - cur[v])
		cur[v] = i
	for i in range(n):
		f[i] = max(f[i], n - cur[i])
		if f[i] < n + 1:
			d[f[i]].append(i)
	ans = []
	m = -2
	for i in range(1, n + 1):
		if d[i]:
			if m == -2:
				m = d[i][0]
			else:
				m = min(d[i][0], m)
			ans.append(m + 1)
		else:
			ans.append(m + 1)
	print(*ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = [float('inf') for x in range(n)]
	hmap = {}
	hm = {}
	for i in range(n):
		if hmap.get(arr[i]) is None:
			hmap[arr[i]] = i
			hm[arr[i]] = i
		else:
			hm[arr[i]] = max(i - hmap[arr[i]] - 1, hm[arr[i]])
			hmap[arr[i]] = i
	for h in hm:
		hm[h] = max(n - hmap[h] - 1, hm[h])
		ans[hm[h]] = min(h, ans[hm[h]])
	mn = ans[0]
	for i in range(n):
		mn = min(mn, ans[i])
		ans[i] = min(mn, ans[i])
	for i in range(n):
		if ans[i] == float('inf'):
			ans[i] = -1
		print(ans[i], end=' ')
	print()


from sys import stdin
input = stdin.readline
from collections import defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	index = defaultdict(lambda : [-1])
	for (i, v) in enumerate(a):
		index[v].append(i)
	res = [-1] * n
	pre = n
	for i in sorted(index.keys()):
		gap = -1
		index[i].append(n)
		for (a, b) in zip(index[i], index[i][1:]):
			gap = max(gap, b - a)
		if gap - 1 < pre:
			for j in range(gap - 1, pre):
				res[j] = i
			pre = gap - 1
	print(' '.join(map(str, res)))
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = I()
	r = [[] for i in range(n + 1)]
	for i in range(n):
		r[l[i]].append(i)
	an = [-1] * (n + 1)
	for i in range(n, 0, -1):
		if r[i]:
			cr = [-1] + r[i]
			pr = n
			x = 0
			for j in range(len(cr) - 1, -1, -1):
				x = max(x, pr - cr[j])
				pr = cr[j]
			an[x] = i
	for i in range(1, n):
		if an[i] != -1:
			if an[i + 1] == -1 or an[i + 1] > an[i]:
				an[i + 1] = an[i]
	print(*an[1:])


import sys
input = sys.stdin.readline
tests = int(input())
for case in range(tests):
	n = int(input())
	ans = [1000000001] * n
	a = list(map(int, input().split()))
	k = dict()
	for i in range(n):
		if a[i] not in k:
			k[a[i]] = [i]
		else:
			k[a[i]].append(i)
	z = dict()
	for key in k:
		d = 0
		if k[key][0] != 0:
			d = max(d, k[key][0] + 1)
		for i in range(1, len(k[key])):
			d = max(d, abs(k[key][i] - k[key][i - 1]))
		if k[key][-1] != n - 1:
			d = max(d, n - k[key][-1])
		if d in z:
			z[d] = min(z[d], key)
		else:
			z[d] = key
	for i in range(len(ans)):
		if i > 0:
			if i + 1 in z:
				ans[i] = min(z[i + 1], ans[i - 1] if ans[i - 1] != -1 and ans[i - 1] != 1000000001 else z[i + 1])
			elif ans[i - 1] == -1 or ans[i - 1] == 1000000001:
				(ans[i], ans[i - 1]) = (-1, -1)
			else:
				ans[i] = ans[i - 1]
		elif i + 1 in z:
			ans[i] = z[i + 1]
		else:
			ans[i] = -1
	print(*ans)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	last = [-1] * (n + 1)
	maxdif = [0] * (n + 1)
	for i in range(n):
		current = a[i]
		maxdif[current] = max(maxdif[current], i - last[current])
		last[current] = i
	for i in range(1, n + 1):
		maxdif[i] = max(maxdif[i], n - last[i])
	ans = []
	curr = maxdif[1]
	for i in range(1, n + 1):
		curr = min(maxdif[i], curr)
		maxdif[i] = curr
	pointer = n
	for i in range(1, n + 1):
		if i < maxdif[pointer]:
			ans.append('-1')
		else:
			while maxdif[pointer - 1] == i:
				pointer -= 1
			ans.append(str(pointer))
	print(' '.join(ans))


def calc(lst, n):
	if not lst:
		return n + 1
	else:
		k = 0
		prev = -1
		for ele in lst:
			k = max(k, ele - prev)
			prev = ele
		k = max(k, n - prev)
		return k
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	indices = [[] for i in range(n + 1)]
	i = 0
	for ele in a:
		indices[ele].append(i)
		i += 1
	prev = n
	ans = [-1 for i in range(n)]
	for x in range(1, n + 1):
		cur = calc(indices[x], n) - 1
		for i in range(cur, prev):
			ans[i] = x
		prev = min(cur, prev)
	print(' '.join([str(x) for x in ans]))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = li()
	index = defaultdict(list)
	for i in set(l):
		index[i].append(-1)
	for i in range(n):
		index[l[i]].append(i)
	ans = [float('inf')] * (n + 1)
	for i in index:
		curr = -float('inf')
		for j in range(1, len(index[i])):
			curr = max(curr, index[i][j] - index[i][j - 1])
		curr = max(curr, n - index[i][-1])
		if curr <= n:
			ans[curr - 1] = min(ans[curr - 1], i)
	for i in range(n):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(n):
		if ans[i] == float('inf'):
			ans[i] = -1
	print(*ans[:-1])


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] + list(map(int, input().split()))
	period = [0 for i in range(n + 1)]
	first = [-1 for i in range(n + 1)]
	last = [-1 for i in range(n + 1)]
	for i in range(1, len(a)):
		b = a[i]
		if first[b] == -1:
			first[b] = i
			last[b] = i
		else:
			period[b] = max(period[b], i - last[b])
			last[b] = i
	for i in range(1, len(period)):
		period[i] = max(period[i], n - last[i] + 1)
	period = period[1:]
	l = sorted(list((e if e[0] > first[e[1]] else (first[e[1]], e[1]) for e in zip(period, range(1, n + 1)) if e[0] > 0)))
	ans = []
	AA = n + 5
	ind = 0
	for i in range(1, n + 1):
		if ind < len(l) and l[ind][0] == i:
			AA = min(AA, l[ind][1])
		ans.append(-1 if AA == n + 5 else AA)
		while ind < len(l) and l[ind][0] == i:
			ind += 1
	print(*ans)


for anynumber in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for (index, i) in enumerate(l):
		if i not in d.keys():
			d[i] = [index + 1, index]
		else:
			d[i] = [max(index - d[i][1], d[i][0]), index]
	for i in d.keys():
		d[i] = max(d[i][0], n - d[i][1])
	ans = [-1 for i in range(n)]
	for i in sorted(d.keys(), reverse=True):
		ans[d[i] - 1] = i
	for i in range(1, n):
		if ans[i] == -1:
			ans[i] = ans[i - 1]
		elif ans[i - 1] != -1:
			if ans[i - 1] < ans[i]:
				ans[i] = ans[i - 1]
	for i in range(n - 1):
		print(ans[i], end=' ')
	print(ans[n - 1])


t = int(input())
ns = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	nums = set(arr)
	dct1 = {}
	dct2 = {num: 0 for num in nums}
	for (idx, el) in enumerate(arr):
		if el in dct1:
			dct2[el] = max(dct2[el], idx - dct1[el])
		else:
			dct2[el] = idx + 1
		dct1[el] = idx
	for el in dct2:
		dct2[el] = max(dct2[el], n - dct1[el])
	ans = []
	temp = sorted(nums, key=lambda x: dct2[x])
	index = 0
	mini = 10 ** 20
	for k in range(1, n + 1):
		while index < len(temp) and dct2[temp[index]] == k:
			mini = min(mini, temp[index])
			index += 1
		if mini == 10 ** 20:
			ans.append(-1)
		else:
			ans.append(mini)
	ns.append(ans)
for el in ns:
	print(' '.join(list(map(str, el))))


import bisect
for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	inf = n
	undef = 2 * n
	mx = [undef] * n
	last = [undef] * n
	for (i, v) in enumerate(arr):
		if mx[v - 1] == undef:
			mx[v - 1] = i + 1
		else:
			mx[v - 1] = max(mx[v - 1], i - last[v - 1])
		last[v - 1] = i
	for i in range(n):
		if mx[i] != undef:
			mx[i] = max(mx[i], n - last[i])
	answers = [-1] * n
	r = n
	for i in range(n):
		for j in range(mx[i] - 1, r):
			answers[j] = i + 1
		r = min(r, mx[i] - 1)
	print(' '.join(map(str, answers)))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	from collections import defaultdict
	store = defaultdict(lambda : [0, -1])
	for i in range(n):
		store[arr[i]][0] = max(store[arr[i]][0], i - store[arr[i]][1])
		store[arr[i]][1] = i
	ans = [float('inf')] * (n + 1)
	for (a, b) in store.items():
		b[0] = max(b[0], n - b[1])
	for (a, b) in store.items():
		if b[0] > 0:
			ans[b[0]] = min(ans[b[0]], ans[b[0] - 1], a)
		else:
			ans[b] = a
	res = float('inf')
	for i in range(1, n + 1):
		if res == float('inf') and ans[i] == float('inf'):
			print(-1, end=' ')
		else:
			res = min(res, ans[i])
			print(res, end=' ')
	print()


import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
for _ in range(II()):
	n = II()
	a = L(I())
	d = []
	l = [T] * (n + 1)
	for i in range(n):
		k = l[a[i]]
		if k == True:
			k = [i + 1, i]
			l[a[i]] = k
		k[0] = max(k[0], i - k[1])
		k[1] = i
	for i in range(1, n + 1):
		if l[i] == True:
			continue
		d.append(i)
		l[i][0] = max(l[i][0], n - l[i][1])
	k = n + 1
	res = []
	for i in d:
		if l[i][0] >= k:
			continue
		res.extend([i] * (k - l[i][0]))
		k = l[i][0]
		if k == 1:
			break
	f = [-1] * (k - 1)
	P(*f, end=' ')
	for i in range(n - k, -1, -1):
		P(res[i], end=' ')
	P()


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in stdin.readline().split()]
	prev = [-1] * (n + 1)
	dist = [0] * (n + 1)
	mi = n
	prev[a[0]] = 0
	for i in range(n):
		temp = i - prev[a[i]]
		prev[a[i]] = i
		dist[a[i]] = max(dist[a[i]], temp)
	prev = [n] * (n + 1)
	prev[a[n - 1]] = n - 1
	for i in range(n - 1, -1, -1):
		temp = prev[a[i]] - i
		prev[a[i]] = i
		dist[a[i]] = max(dist[a[i]], temp)
	ans = [-1] * n
	for i in range(1, n + 1):
		if ans[dist[i] - 1] == -1 and dist[i] != 0:
			ans[dist[i] - 1] = i
	mini = -1
	for i in range(n):
		if ans[i] != -1:
			if mini != -1:
				mini = min(mini, ans[i])
				ans[i] = min(mini, ans[i])
			else:
				mini = ans[i]
		elif mini != -1 and ans[i] == -1:
			ans[i] = mini
	print(*ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(ele, end='\n')
for _ in range(L()[0]):
	n = L()[0]
	A = L()
	d = {}
	for i in range(n):
		if A[i] not in d:
			d[A[i]] = []
		d[A[i]].append(i)
	for ele in d:
		p = []
		(st, end) = (d[ele][0], d[ele][-1])
		for i in range(1, len(d[ele])):
			p.append(d[ele][i] - d[ele][i - 1])
		if not p:
			d[ele] = max(d[ele][0] + 1, n - d[ele][0])
		else:
			d[ele] = max(p)
			d[ele] = max(d[ele], st + 1, n - end)
	B = [-1 for i in range(n)]
	C = [[d[ele] - 1, ele] for ele in d]
	C.sort()
	for (x, y) in C:
		B[x] = y if B[x] == -1 else min(B[x], y)
	mn = 10 ** 10
	for i in range(n):
		if B[i] == -1 and mn == 10 ** 10:
			continue
		if B[i] == -1:
			B[i] = mn
			continue
		mn = min(B[i], mn)
		B[i] = mn
	print(*B)
endtime = time.time()


import sys
from collections import deque, defaultdict, namedtuple
import heapq
from math import sqrt, factorial, gcd, ceil, atan, pi
from itertools import permutations

def input():
	return sys.stdin.buffer.readline().decode('utf-8').strip()
import string
import operator
import random
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	d = defaultdict(lambda : -1)
	m = defaultdict(int)
	for i in range(n):
		x = a[i]
		m[x] = max(m[x], i - d[x])
		d[x] = i
	for i in range(n):
		x = a[i]
		m[x] = max(m[x], n - d[x])
	rm = defaultdict(lambda : INF)
	for k in m:
		rm[m[k]] = min(rm[m[k]], k)
	ans = INF
	for i in range(1, n + 1):
		ans = min(rm[i], ans)
		if ans == INF:
			print(-1, end=' ')
		else:
			print(ans, end=' ')
	print()
T = 1
T = int(input())
for case in range(1, T + 1):
	ans = solve()


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = [[-1, -1]] * (n + 1)
	for i in range(n):
		y = a[i]
		s = max(d[y][1], i - d[y][0])
		d[y] = [i, s]
	for i in range(n + 1):
		d[i][1] = max(d[i][1], n - d[i][0])
	y = [i for i in range(1, n + 1)]
	y.sort(key=lambda x: d[x][1])
	ans = [0] * n
	z = 0
	p = 10 ** 6
	for i in range(1, n + 1):
		while z < n and i >= d[y[z]][1]:
			p = min(p, y[z])
			z += 1
		if p == 10 ** 6:
			ans[i - 1] = -1
		else:
			ans[i - 1] = p
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
for _ in range(N()):
	n = N()
	a = RLL()
	res = [-1] * n
	dic = dc(list)
	for i in range(n):
		key = a[i]
		dic[key].append(i)
	now = n
	for i in range(1, n + 1):
		if i in dic:
			gap = dic[i][0] + 1
			for j in range(1, len(dic[i])):
				gap = max(gap, dic[i][j] - dic[i][j - 1])
				if gap > now:
					break
			gap = max(gap, n - dic[i][-1])
			if gap <= now:
				res[gap - 1:now] = [i] * (now - gap + 1)
				now = gap - 1
				if now == 0:
					break
	print_list(res)


s = int(input())
for _ in range(s):
	n = int(input())
	a = [int(i) - 1 for i in input().split(' ')]
	b = a[::-1]
	diff = [0] * n
	cur = [-1] * n
	for i in range(n):
		diff[a[i]] = max(diff[a[i]], i - cur[a[i]])
		cur[a[i]] = i
	cur = [-1] * n
	for i in range(n):
		diff[b[i]] = max(diff[b[i]], i - cur[b[i]])
		cur[b[i]] = i
	for i in range(n):
		if diff[i] == 0:
			diff[i] = 10 ** 6
	diff2 = [(diff[i] - 1, i + 1) for i in range(n)] + [(999999, 999999)]
	diff2.sort()
	ans = [-1] * n
	loc = 0
	now = diff2[0][1]
	for i in range(diff2[0][0], n):
		while loc < n - 1 and diff2[loc + 1][0] <= i:
			loc += 1
			now = min(now, diff2[loc][1])
		ans[i] = now
	print(' '.join((str(i) for i in ans)))


from sys import stdin, stdout
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	idx = [[-1] for i in range(n + 1)]
	for i in range(n):
		idx[a[i]].append(i)
	for i in range(1, n + 1):
		idx[i].append(n)
	mn = [[0, i + 1] for i in range(n)]
	for i in range(1, n + 1):
		for j in range(1, len(idx[i])):
			mn[i - 1][0] = max(mn[i - 1][0], idx[i][j] - idx[i][j - 1])
	mn.sort()
	p = 0
	cur = 10000000
	for k in range(1, n + 1):
		while p < n:
			if mn[p][0] > k:
				break
			cur = min(cur, mn[p][1])
			p += 1
		if cur == 10000000:
			print(-1, end=' ')
		else:
			print(cur, end=' ')
	print()


from __future__ import division, print_function
import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	INF = float('inf')
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(ai) for ai in input().split()]
		last = defaultdict(lambda : -1)
		poss = defaultdict(int)
		for (i, j) in enumerate(a):
			poss[j] = max(poss[j], i - last[j])
			last[j] = i
		for key in last:
			poss[key] = max(poss[key], n - last[key])
		sol = [INF] * n
		for (key, value) in poss.items():
			sol[value - 1] = min(sol[value - 1], key)
		for i in range(1, n):
			sol[i] = min(sol[i - 1], sol[i])
		print(*[-1 if i == INF else i for i in sol])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	distances = {}
	for (ind, a_i) in enumerate(a):
		if a_i not in distances:
			distances[a_i] = [ind, ind]
		else:
			distances[a_i] = [ind, max(ind - distances[a_i][0] - 1, distances[a_i][1])]
	for a_i in distances:
		distances[a_i][1] = max(len(a) - 1 - distances[a_i][0], distances[a_i][1])
	accepted_values = sorted(distances, key=lambda x: (distances[x][1], x))
	found_distances = {}
	for value in accepted_values:
		if distances[value][1] not in found_distances:
			found_distances[distances[value][1]] = value
	minimum = float('inf')
	start = -1
	ans = []
	for ind in range(n):
		if start == -1 and ind in found_distances:
			minimum = min(minimum, found_distances[ind])
			ans.append(minimum)
			start = ind
		elif start == -1 and ind not in found_distances:
			ans.append(-1)
		elif start >= 0 and ind in found_distances:
			minimum = min(minimum, found_distances[ind])
			ans.append(minimum)
			start = ind
		elif start >= 0 and ind not in found_distances:
			minimum = min(minimum, found_distances[start])
			ans.append(minimum)
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	last_same = {}
	for a in arr:
		last_same[a] = (-1, 1)
	for (i, a) in enumerate(arr):
		last_same[a] = (i, max(last_same[a][1], i - last_same[a][0]))
	for a in last_same.keys():
		last_same[a] = (last_same[a][0], max(last_same[a][1], len(arr) - last_same[a][0]))
	ans = [-1] * len(arr)
	for a in sorted(list(last_same.keys())):
		pos = last_same[a][1] - 1
		while pos < len(ans) and ans[pos] == -1:
			ans[pos] = a
			pos += 1
	print(' '.join(map(str, ans)))


def read_line():
	return list(map(int, input().split()))

def A(d, i, x):
	if x not in d:
		d[x] = [-1, i]
		return
	d[x][0] = max(i - d[x][1], d[x][0])
	d[x][1] = i
T = int(input())
for _ in range(T):
	n = int(input())
	l = read_line()
	d = {}
	s = {}
	for x in l:
		if x in s:
			continue
		s[x] = 1
		A(d, -1, x)
	for (i, x) in enumerate(l):
		A(d, i, x)
	s = {}
	for x in l:
		if x in s:
			continue
		s[x] = 1
		A(d, n, x)
	ans = [None] * (n + 1)
	for x in sorted(d.keys()):
		val = x
		gap = d[x][0]
		if ans[gap] is None or ans[gap] > val:
			ans[gap] = val
	for i in range(2, n + 1):
		if ans[i - 1] is None:
			continue
		if ans[i] is None:
			ans[i] = ans[i - 1]
		ans[i] = min(ans[i], ans[i - 1])
	print(' '.join(map(lambda x: '-1' if x is None else str(x), ans[1:])))


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	adjli = [[-1] for i in range(N + 1)]
	for (i, a) in enumerate(A):
		adjli[a].append(i)
	for i in range(1, N + 1):
		adjli[i].append(N)
	ans = [INF] * (N + 1)
	for i in range(1, N + 1):
		mx = 0
		if len(adjli[i]) >= 3:
			for j in range(len(adjli[i]) - 1):
				mx = max(mx, adjli[i][j + 1] - adjli[i][j])
			if mx != 0:
				ans[mx] = min(ans[mx], i)
	for i in range(1, N + 1):
		ans[i] = min(ans[i], ans[i - 1])
	ans = [a if a != INF else -1 for a in ans]
	print(*ans[1:])


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	dic = dd(list)
	ch = sorted(list(set(arr)))
	for i in ch:
		dic[i].append(-1)
	for i in range(n):
		dic[arr[i]].append(i)
	for i in ch:
		dic[i].append(n)
	ans = [None] * (n + 1)
	ans[n] = min(arr)
	dic2 = dd(lambda : float('inf'))
	for i in ch:
		diff = -float('inf')
		for j in range(len(dic[i]) - 1):
			diff = max(diff, dic[i][j + 1] - dic[i][j])
		if diff == -float('inf'):
			pass
		else:
			dic2[diff] = min(dic2[diff], i)
	cur = float('inf')
	for i in range(1, n):
		cur = min(cur, dic2[i])
		if cur == float('inf'):
			ans[i] = -1
		else:
			ans[i] = cur
	ans.pop(0)
	print(*ans)


from sys import stdin, stdout
from collections import defaultdict
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ni = defaultdict(list)
	sl_val = {}
	cur = -1
	for i in range(n):
		ni[a[i]] += [i]
	for val in ni:
		l = ni[val]
		mx = l[0] + 1
		for (p1, p2) in zip(l, l[1:]):
			mx = max(mx, p2 - p1)
		mx = max(mx, n - l[-1])
		sl_val[mx] = min(sl_val.get(mx, float('inf')), val)
	for i in range(n):
		if i + 1 in sl_val:
			cur = min(cur if cur != -1 else float('inf'), sl_val[i + 1])
		stdout.write(str(cur) + ' ')
	print()


import sys, os, io
input = sys.stdin.readline
T = int(input())
from collections import defaultdict
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	max_dif = defaultdict(lambda : 0)
	bef = defaultdict(lambda : -1)
	for i in range(n):
		max_dif[A[i]] = max(max_dif[A[i]], i - bef[A[i]])
		bef[A[i]] = i
	for k in max_dif.keys():
		max_dif[k] = max(max_dif[k], n - bef[k])
	lis = sorted(max_dif.items(), key=lambda x: (x[1], x[0]))
	lis2 = lis[1:] + [(n + 1, n + 1)]
	ans = [0] * n
	for j in range(lis[0][1] - 1):
		ans[j] = -1
	cum = n
	for ((k, v), (k1, v1)) in zip(lis, lis2):
		cum = min(cum, k)
		for j in range(v - 1, v1 - 1):
			ans[j] = cum
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		rec = defaultdict(int)
		pre = defaultdict(int)
		for i in range(n):
			now = arr[i]
			if now in pre:
				rec[now] = max(rec[now], i - pre[now])
			else:
				rec[now] = max(rec[now], i + 1)
			pre[now] = i
		for i in pre:
			rec[i] = max(rec[i], n - pre[i])
		res = [-1] * n
		for i in rec:
			gp = rec[i]
			if gp - 1 < n:
				if res[gp - 1] == -1:
					res[gp - 1] = i
				else:
					res[gp - 1] = min(res[gp - 1], i)
		mi = 10 ** 9
		for i in range(n):
			if res[i] != -1:
				mi = min(res[i], mi)
			if mi != 10 ** 9:
				if res[i] != -1:
					res[i] = min(res[i], mi)
				else:
					res[i] = mi
		print(*res)
main()


for tc in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	prev = [-1 for i in range(n + 1)]
	maxGap = [-1 for i in range(n + 1)]
	for i in range(len(s)):
		if i - prev[s[i]] > maxGap[s[i]]:
			maxGap[s[i]] = i - prev[s[i]]
		prev[s[i]] = i
	for i in range(n):
		if maxGap[i] != -1 and n - prev[i] > maxGap[i]:
			maxGap[i] = n - prev[i]
	k = [1000000 for i in range(n)]
	for i in range(1, len(maxGap)):
		if maxGap[i] != -1:
			if k[maxGap[i] - 1] > i:
				k[maxGap[i] - 1] = i
	best = 2000000
	for i in range(len(k)):
		if k[i] == 1000000 and best == 2000000:
			k[i] = -1
		elif k[i] > best:
			k[i] = best
		else:
			best = k[i]
	print(' '.join(map(str, k)))


import sys
input = sys.stdin.readline
for i in ' ' * int(input()):
	n = int(input())
	L = list(map(int, input().split()))
	L1 = [0] * n
	L2 = [-1] * n
	for i in range(n):
		k = L[i]
		L1[k - 1] = max(L1[k - 1], i - L2[k - 1])
		L2[k - 1] = i
	for i in range(n):
		k = L[i]
		L1[k - 1] = max(L1[k - 1], n - L2[k - 1])
	checkL = [-1] * n
	for i in range(n):
		if checkL[L1[i] - 1] == -1 and L1[i] != 0:
			checkL[L1[i] - 1] = i + 1
	rem = -1
	for i in range(n):
		if checkL[i] == -1:
			print(rem, end=' ')
		else:
			if rem != -1 and rem < checkL[i]:
				print(rem, end=' ')
				continue
			print(checkL[i], end=' ')
			rem = checkL[i]
	print()


import math
import collections
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	l1 = [0] * n
	d = {}
	for i in range(n):
		if l[i] not in d:
			if i == 0:
				d[l[i]] = [i]
			else:
				d[l[i]] = [-1, i]
		else:
			d[l[i]].append(i)
	for i in d:
		if d[i][-1] != n - 1:
			d[i].append(n)
	m = n
	d = collections.OrderedDict(sorted(d.items()))
	for i in d:
		d1 = 0
		for j in range(len(d[i]) - 1):
			d1 = max(d1, d[i][j + 1] - d[i][j])
		for j in range(d1 - 1, m):
			l1[j] = i
		m = min(m, d1 - 1)
	for i in range(m):
		l1[i] = -1
	print(*l1)


def cal(arr):
	return max((arr[i] - arr[i - 1] for i in range(1, len(arr))))
for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	dic = {}
	for i in range(len(arr)):
		if arr[i] in dic:
			dic[arr[i]].append(i + 1)
		else:
			dic[arr[i]] = [0, i + 1]
	for i in dic:
		dic[i].append(len(arr) + 1)
	ans = [10 ** 9] * len(arr)
	for i in dic:
		temp = cal(dic[i])
		ans[temp - 1] = min(ans[temp - 1], i)
	for i in range(1, len(ans)):
		ans[i] = min(ans[i], ans[i - 1])
	for i in range(0, len(ans)):
		if ans[i] == 10 ** 9:
			ans[i] = -1
	print(*ans)


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	d = {}
	ind = {}
	for i in range(n):
		if m[i] in d:
			d[m[i]] = max(d[m[i]], i - ind[m[i]])
			ind[m[i]] = i
		else:
			ind[m[i]] = i
			d[m[i]] = i + 1
	for i in range(n):
		if ind[m[i]] == i:
			d[m[i]] = max(d[m[i]], n - i)
	a = [float('inf')] * n
	for i in d:
		a[d[i] - 1] = min(a[d[i] - 1], i)
	for i in range(1, n):
		a[i] = min(a[i], a[i - 1])
	for i in range(n):
		if a[i] == float('inf'):
			a[i] = -1
	print(*a)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	pre = {}
	gap = {}
	for (i, ai) in enumerate(a):
		if ai in pre:
			gap[ai] = max(gap[ai], i - pre[ai] - 1)
		else:
			gap[ai] = i
		pre[ai] = i
	for ai in pre:
		gap[ai] = max(gap[ai], n - pre[ai] - 1)
	ans = [(gap[ai], ai) for ai in gap]
	ans.sort()
	p = 0
	cur = int(1000000000.0)
	for i in range(n):
		while p < len(ans) and ans[p][0] <= i:
			cur = min(cur, ans[p][1])
			p += 1
		print(-1 if cur == int(1000000000.0) else cur, end='')
		print(end=' ' if i != n - 1 else '')
	print()


import sys
from collections import defaultdict
if len(sys.argv) >= 2 and sys.argv[1] == 'LOCAL':
	sys.stdin = open('input.txt')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
output = sys.stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	res = [n + 1] * (n + 1)
	occurs = defaultdict(list)
	for i in range(n):
		occurs[arr[i]].append(i + 1)
	maxAway = [0] * (n + 1)
	for i in range(1, n + 1):
		l = occurs[i]
		mx = 0
		if len(l) == 0:
			continue
		for j in range(len(l)):
			if j == 0:
				mx = max(mx, l[j])
			if j == len(l) - 1:
				mx = max(mx, n - l[j] + 1)
				mx = max(mx, l[j] - l[j - 1])
			if j >= 1:
				mx = max(mx, l[j] - l[j - 1])
		res[mx] = min(res[mx], i)
	best = n + 1
	for i in range(1, n + 1):
		if res[i] == n + 1:
			if best != n + 1:
				output(str(best) + ' ')
			else:
				output('-1' + ' ')
		else:
			best = min(best, res[i])
			output(str(best) + ' ')
	output('\n')


INF = 10 ** 15
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {i: 0 for i in arr}
	last = {i: -1 for i in arr}
	for i in range(n):
		if last[arr[i]] == -1:
			d[arr[i]] = max(d[arr[i]], i + 1)
		else:
			d[arr[i]] = max(d[arr[i]], i - last[arr[i]])
		last[arr[i]] = i
	for i in last.keys():
		d[i] = max(d[i], n - last[i])
	d2 = {}
	for (k, v) in d.items():
		if v not in d2:
			d2[v] = INF
		d2[v] = min(d2[v], k)
	ans = [INF] * n
	for i in range(1, n + 1):
		can = INF
		if i != 1:
			can = ans[i - 2]
		if i in d2.keys():
			can = min(can, d2[i])
		ans[i - 1] = can
	for i in range(n):
		if ans[i] == INF:
			ans[i] = -1
	print(*ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	max_dist = defaultdict(lambda : -1)
	last_index = defaultdict(lambda : -1)
	n = int(input())
	nums = list(map(int, input().split()))
	for (i, num) in enumerate(nums):
		max_dist[num] = max(max_dist[num], i - last_index[num])
		last_index[num] = i
	for key in max_dist.keys():
		max_dist[key] = max(max_dist[key], n - last_index[key])
	answer = [float('inf')] * n
	for key in max_dist.keys():
		value = max_dist[key]
		answer[value - 1] = min(answer[value - 1], key)
	for i in range(1, n):
		answer[i] = min(answer[i], answer[i - 1])
	for a in answer:
		if a == float('inf'):
			print(-1, end=' ')
		else:
			print(a, end=' ')
	print()


from math import sqrt, ceil
from collections import defaultdict

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	hash = defaultdict(list)
	for i in range(n):
		hash[l[i]].append(i + 1)
	if len(set(l)) == 1:
		print(*[min(l)] * n)
		return
	ans = defaultdict(lambda : 10 ** 18)
	for i in hash:
		prev = 0
		maxi = -10 ** 18
		for j in hash[i]:
			z = j - prev
			maxi = max(maxi, z)
			prev = j
		z = n - prev + 1
		maxi = max(maxi, z)
		ans[maxi] = min(i, ans[maxi])
	fin = [-1]
	for i in range(1, n):
		if ans[i + 1] != 10 ** 18:
			if fin[i - 1] == -1:
				fin.append(ans[i + 1])
			else:
				fin.append(min(fin[i - 1], ans[i + 1]))
		elif fin[i - 1] == -1:
			fin.append(-1)
		else:
			fin.append(fin[i - 1])
	print(*fin)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	STEP = [[] for i in range(n + 1)]
	for i in range(n):
		STEP[A[i]].append(i)
	ANS = [1 << 60] * (n + 3)
	for i in range(n + 1):
		NOW = -1
		MAX = -1
		for k in STEP[i]:
			MAX = max(MAX, k - NOW)
			NOW = k
		MAX = max(MAX, n - NOW)
		ANS[MAX] = min(ANS[MAX], i)
	ANSL = []
	for i in range(1, n + 1):
		ANS[i] = min(ANS[i], ANS[i - 1])
		if ANS[i] == 1 << 60:
			ANSL.append(-1)
		else:
			ANSL.append(ANS[i])
	print(*ANSL)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = [[-1] for i in range(n)]
	ans = []
	cursz = n
	for i in range(n):
		l[a[i] - 1].append(i)
	for i in range(n):
		if cursz == 0 or len(ans) == n:
			break
		mxdiff = -1
		if len(l[i]) == 1:
			continue
		else:
			l[i].append(n)
			for j in range(len(l[i]) - 1):
				mxdiff = max(mxdiff, l[i][j + 1] - l[i][j])
			if mxdiff <= cursz:
				for j in range(cursz - mxdiff + 1):
					ans.append(i + 1)
				cursz = mxdiff - 1
	for i in range(n - len(ans)):
		print(-1, end=' ')
	for i in range(len(ans) - 1, -1, -1):
		print(ans[i], end=' ')
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		if ar[i] in dic:
			dic[ar[i]].append(i)
		else:
			dic[ar[i]] = [-1, i]
	for i in dic:
		dic[i].append(n)
	ans = [-1] * (n + 1)
	for i in dic:
		ma = -float('inf')
		for j in range(1, len(dic[i])):
			ma = max(ma, dic[i][j] - dic[i][j - 1])
		if ans[ma] != -1:
			ans[ma] = min(ans[ma], i)
		else:
			ans[ma] = i
	pre = -1
	for i in range(1, n + 1):
		if pre == -1:
			if ans[i] != -1:
				pre = ans[i]
		elif ans[i] != -1:
			ans[i] = min(pre, ans[i])
			pre = min(pre, ans[i])
		else:
			ans[i] = pre
	print(*ans[1:])


import sys
r = sys.stdin.readline
for _ in range(int(r())):
	n = int(r())
	a = [*map(int, r().split())]
	dis = [0] * n
	loc = [-1] * n
	for i in range(n):
		t = a[i] - 1
		dis[t] = max(dis[t], i - loc[t])
		loc[t] = i
	dis = [max(dis[i], n - loc[i]) for i in range(n)]
	graph = sorted(zip(dis, range(n)))
	ans = []
	p = 0
	m = -2
	for i in range(1, n + 1):
		while i > graph[p][0]:
			p += 1
		if i == graph[p][0] and (m < 0 or graph[p][1] < m):
			m = graph[p][1]
		ans.append(m + 1)
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prime_factors(x):
	s = set()
	n = x
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			s.add(i)
		i += 1
	if n > 1:
		s.add(n)
	return s
from collections import Counter
import heapq
from collections import Counter
from bisect import bisect_right
import heapq
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	v = [-1] * (n + 5)
	d = {}
	ans = [-1] * (n + 2)
	for i in range(n):
		if v[arr[i]] != -1:
			if arr[i] in d:
				d[arr[i]] = max(d[arr[i]], i + 1 - v[arr[i]])
				v[arr[i]] = i + 1
			else:
				d[arr[i]] = max(v[arr[i]], i + 1 - v[arr[i]])
				v[arr[i]] = i + 1
		else:
			v[arr[i]] = i + 1
	for i in range(n):
		if v[arr[i]] != -1:
			if arr[i] in d:
				d[arr[i]] = max(d[arr[i]], n + 1 - v[arr[i]])
			else:
				d[arr[i]] = max(v[arr[i]], n + 1 - v[arr[i]])
		cnt = d[arr[i]]
		if ans[cnt] == -1:
			ans[cnt] = arr[i]
		else:
			ans[cnt] = min(ans[cnt], arr[i])
	value = n + 100
	for i in range(1, n + 1):
		if ans[i] != -1:
			ans[i] = min(ans[i], value)
			value = min(value, ans[i])
		elif value <= n:
			ans[i] = value
	if arr == [arr[0]] * n:
		print(*arr)
	else:
		ans[n] = min(arr)
		print(*ans[1:n + 1])


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		m = {}
		for i in range(n):
			if a[i] not in m:
				m[a[i]] = [0]
			m[a[i]].append(i + 1)
		ans = [inf] * (n + 1)
		for i in m.keys():
			x = m[i]
			mxdiff = 0
			x.append(n + 1)
			for j in range(1, len(x)):
				mxdiff = max(mxdiff, x[j] - x[j - 1])
			ans[mxdiff] = min(ans[mxdiff], i)
		res = []
		x = inf
		for i in range(1, n + 1):
			x = min(x, ans[i])
			if x == inf:
				res.append(-1)
			else:
				res.append(x)
		print(*res)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	last = [-1 for _ in range(n)]
	maxlen = [-1 for _ in range(n)]
	for i in range(n):
		x = a[i] - 1
		maxlen[x] = max(maxlen[x], i - last[x])
		last[x] = i
	maxlen = [max(maxlen[i], n - last[i]) for i in range(n)]
	sol = [-1 for _ in range(n + 2)]
	for i in range(n):
		if sol[maxlen[i]] == -1:
			sol[maxlen[i]] = i + 1
	sol = sol[1:len(sol) - 1]
	if sol[0] == -1:
		sol[0] = n + 2
	for i in range(1, n):
		if sol[i] == -1:
			sol[i] = n + 2
		sol[i] = min(sol[i], sol[i - 1])
	for i in range(n):
		if sol[i] == n + 2:
			sol[i] = -1
		else:
			break
	print(' '.join([str(i) for i in sol]))


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	dis = [0] * n
	dic = {}
	res = [-1] * n
	for i in range(n):
		tmp = arr[i] - 1
		if tmp not in dic.keys():
			dis[tmp] = max(dis[tmp], i + 1)
		else:
			dis[tmp] = max(dis[tmp], i - dic[tmp])
		dic[tmp] = i
	for key in dic.keys():
		dis[key] = max(dis[key], n - dic[key])
	prev = n
	for i in range(n):
		if dis[i] == 0:
			continue
		else:
			start = dis[i] - 1
			temp = start
			while start < prev:
				res[start] = i + 1
				start += 1
			prev = min(prev, temp)
	print(*res)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	from collections import defaultdict
	mp = defaultdict(list)
	pst = {}
	for i in range(n):
		if len(mp[a[i]]) == 0:
			mp[a[i]].append(i)
			pst[a[i]] = i
		else:
			pst[a[i]] = max(pst[a[i]], i - mp[a[i]][-1] - 1)
			mp[a[i]].append(i)
	for i in mp.keys():
		pst[i] = max(pst[i], n - 1 - mp[i][-1])
	lst = n
	res = [-1] * n
	for i in sorted(pst.keys()):
		for j in range(pst[i], lst):
			res[j] = i
		lst = min(lst, pst[i])
	print(*res)


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	db = {}
	for i in range(n):
		if a[i] not in db:
			db[a[i]] = [0, i + 1]
		else:
			db[a[i]].append(i + 1)
	for k in db.keys():
		db[k].append(n + 1)
	gaps = {}
	for (k, l) in db.items():
		dif = 0
		for i in range(len(l) - 1):
			dif = max(l[i + 1] - l[i], dif)
		if dif not in gaps:
			gaps[dif] = k
		else:
			gaps[dif] = min(k, gaps[dif])
	x = -1
	ans = []
	for i in range(1, n + 1):
		if i in gaps:
			if x == -1:
				x = gaps[i]
			elif ans[-1] > gaps[i]:
				x = gaps[i]
		ans.append(x)
	print(*ans)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	minn = {}
	maxx = {}
	prev = {}
	for i in range(n):
		prev[a[i]] = 0
		maxx[a[i]] = 0
	for i in range(1, n + 1):
		diff = i - prev[a[i - 1]]
		maxx[a[i - 1]] = max(maxx[a[i - 1]], diff)
		prev[a[i - 1]] = i
	for i in set(a):
		diff = n + 1 - prev[i]
		maxx[i] = max(maxx[i], diff)
	f = 10 ** 18
	for i in maxx:
		if maxx[i] in minn:
			minn[maxx[i]] = min(minn[maxx[i]], i)
		else:
			minn[maxx[i]] = i
		f = min(f, maxx[i])
	ans = [-1] * n
	curr = minn[f]
	for i in range(f, n + 1):
		if i not in minn:
			ans[i - 1] = curr
			continue
		curr = min(curr, minn[i])
		ans[i - 1] = curr
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ind = [[] for i in range(n)]
	for i in range(n):
		ind[a[i] - 1].append(i)
	freq = [int(100000000.0)] * n
	for i in range(n):
		if ind[i] == []:
			continue
		mx = 0
		start = -1
		for j in range(len(ind[i])):
			mx = max(mx, ind[i][j] - start)
			start = ind[i][j]
		mx = max(mx, n - start)
		freq[mx - 1] = min(freq[mx - 1], i + 1)
	for i in range(n):
		if freq[i] < int(100000000.0):
			start = i
			break
		freq[i] = -1
	m = 100000000.0
	for i in range(start, n):
		m = min(m, freq[i])
		freq[i] = m
	print(*freq)