#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, k;
cin >> n >> k;
vector<int> arr(n);
for(int i = 0; i < n; i++)
cin >> arr[i];
sort(arr.begin(), arr.end());
int maxSum = 0;
int l = 0, r = n-1, pivot;
for(int i = 0; i < n; i++){
l = 0;
r = n-1;
while(l < r){
pivot = (l+r)/2;
long long power = pow(arr[i], arr[pivot]);
if(power == k && arr[i] != arr[pivot]){
maxSum = max(maxSum, arr[pivot]+arr[i]);
break;
}
if(power <= k)
l = r+1;
if(power > k)
r = l-1;
}
}
cout << maxSum << endl;
}
int main(){
int t; cin >> t;
while(t--)
solve();
return 0;
}
Copy