#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define fi first
#define sc second
#define endl '\n'
#define gcd(x, y) (__gcd(x, y))
#define lcm(x, y) ((x/gcd(x, y))*y)
#define mem(a,b) memset(a, b, sizeof(a))
#define de(x) cerr<<#x<<" :: "<<x<<" "<<endl
bool cmp (pair<int,int>a,pair<int,int>b) {
if(a.second == b.second) {
return a.first>b.first;
}
return a.second<b.second;
}
void solve()
{
int n;
cin>>n;
vector<int>v(n);
vector<pair<int,int>>v1(n);
for(int i =0;i<n;i++){
cin>>v[i];
v1[i].first=v[i];
}
int k;
cin>>k;
for(int i =0;i<n;i++){
int cnt=0;
for(int j =1;j<=v[i];j++){
if(v[i]%j==0)cnt++;
}
v1[i].second=cnt;
cnt=0;
}
sort(all(v1),cmp);
cout<<v1[k-1].first<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}