#include using namespace std; using ll = long long; using ull = unsigned long long; constexpr int MAXLEN = 1 << 18; template int solve(int N, int S, vector &a) { if (len <= S) return solve(N, S, a); bitset dp; dp[0] = 1; int i = 0; while(i < N && 2 * a[i] <= S) { int p = i; while(i < N && a[i] == a[p]) i++; int cnt = i - p; for(int take = 1; cnt > 0; take *= 2) { int D = min(take, cnt); long long shift = (ll)(a[p]) * D; cnt -= D; if(shift <= S) dp |= dp << shift; } } int j = S; while(!dp[j]) j--; int ans = j; while(i < N){ j = min(j, S - a[i]); while(!dp[j]) j--; ans = max(ans, j + a[i++]); } return ans; } array tb; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--) { int N, S, g = 0; cin >> N >> S; vector a(N); for(auto &&v : a) cin >> v; sort(a.begin(), a.end()); while(!a.empty() && a.back() > S) a.pop_back(); N = a.size(); ll tot = 0; for(auto &&v : a){ tot += v; g = gcd(g, v); } if(tot <= S){ cout << tot << '\n'; continue; } if(N <= 14){ int ans = 0; for(int i = 0; i < N; i++) tb[1 << i] = a[i]; for(int i = 1; i < (1 << N); i++){ int b = i & -i; tb[i] = tb[i ^ b] + tb[b]; if(tb[i] <= S) ans = max(ans, tb[i]); } cout << ans << '\n'; continue; } if(g >= 2){ S /= g; for(auto &&v : a) v /= g; } cout << g * solve<16>(N, S, a) << '\n'; } }