#include using namespace std; void solve() { int N; long long X; cin >> N >> X; unordered_map dp, ep; dp[0] = 0; for(int i = 0; i < N; i++) { int c; cin >> c; long long x = X & ((1LL << c) - 1); long long y = X & (1LL << c); if(y != 0) continue; for(const auto [l, r] : dp) { long long l2 = - 1 - x; long long r2 = (1LL << c) - x; if(r2 > r) ep[l] = r2; else ep[l] = r; if(X < (1LL << c)) continue; if(l2 < l) ep[l2] = r; else ep[l] = r; } swap(dp, ep); ep.clear(); } long long ans = 3LL << 60; for(const auto &[l, r] : dp) { ans = min(ans, 2 * (r - l)); } cout << ans << "\n"; } int main() { int T; cin >> T; while(T--) solve(); }