#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n, k;
cin >> n >> k;
int g = 0;
for(int i = 0; i < n; i++){
int x;
cin >> x;
g = __gcd(g, x);
}
if(n == 1){
cout << k - (k <= g) << "\n";
return;
}
int cur = 0;
int cnt = 0;
for(int i = 1; i < n; i++){
if(cnt + (g - 1) >= k){
cout << cur + (k - cnt) << "\n";
return;
}
cur += g;
cnt += (g - 1);
}
cout << cur + (k - cnt) << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7Cgp2b2lkIHNvbHZlKCl7CglpbnQgbiwgazsKCWNpbiA+PiBuID4+IGs7CglpbnQgZyA9IDA7CgoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJaW50IHg7CgkJY2luID4+IHg7CgkJZyA9IF9fZ2NkKGcsIHgpOwoJfQoJaWYobiA9PSAxKXsKCQljb3V0IDw8IGsgLSAoayA8PSBnKSA8PCAiXG4iOwoJCgkJcmV0dXJuOwoJfQoJCglpbnQgY3VyID0gMDsKCWludCBjbnQgPSAwOwoJCglmb3IoaW50IGkgPSAxOyBpIDwgbjsgaSsrKXsKCQlpZihjbnQgKyAoZyAtIDEpID49IGspewoJCQljb3V0IDw8IGN1ciArIChrIC0gY250KSA8PCAiXG4iOwoJCQlyZXR1cm47CgkJfQoJCWN1ciArPSBnOwoJCWNudCArPSAoZyAtIDEpOwoJfQoJY291dCA8PCBjdXIgKyAoayAtIGNudCkgPDwgIlxuIjsKfQoKaW50IG1haW4oKXsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoJY2luLnRpZShudWxscHRyKTsKCQoJaW50IHQgPSAxOwoJY2luID4+IHQ7CgkKCWZvcihpbnQgaSA9IDE7IGkgPD0gdDsgaSsrKXsKCQlzb2x2ZSgpOwoJfQoJcmV0dXJuIDA7Cn0=