def count_divisors(n):
count = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
count += 2
if i == n // i:
count -= 1
return count
def compare(x, y):
if count_divisors(x) < count_divisors(y):
return -1
elif count_divisors(x) > count_divisors(y):
return 1
else:
if x > y:
return -1
elif x < y:
return 1
else:
return 0
def sort_array(arr):
return sorted(arr, key=lambda x: (count_divisors(x), -x))
def print_kth_number(arr, k):
sorted_arr = sort_array(arr)
print(sorted_arr[k-1])
T = int(input())
for _ in range(T):
N = int(input())
arr = list(map(int, input().split()))
k = int(input())
print_kth_number(arr, k)