#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int mx = 10003;
vector<int> f(mx, 1);
void calc () {
for (int i = 2; i < mx; i++) {
for (int j = i; j < mx; j += i) {
f[j] += 1;
}
}
}
void solve(int cs) {
int n;
cin >> n;
vector<array<int,2>> a(n);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i][1] = x;
a[i][0] = f[x];
}
sort(a.begin(), a.end(), [&](auto &i, auto &j){
if (i[0] == j[0]) {
return i[1] > j[1];
} else return i[0] < j[0];
});
int k;
cin >> k;
cout << a[k - 1][1] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1; calc();
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}