#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; constexpr int INF = 1e9; constexpr ll LINF = 1e18; string YesNo(bool cond) { return cond ? "Yes" : "No"; } string YESNO(bool cond) { return cond ? "YES" : "NO"; } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; } template T bisect(T ok, T ng, const F& f) { while (abs(ok - ng) > 1) { T mid = min(ok, ng) + (abs(ok - ng) >> 1); (f(mid) ? ok : ng) = mid; } return ok; } template T floor_div(const T a, const T b) { assert(b != 0); return a / b - static_cast((a ^ b) < 0 && a % b != 0); } template T ceil_div(const T a, const T b) { assert(b != 0); return a / b + static_cast((a ^ b) >= 0 && a % b != 0); } template bool a_mul_b_eq_c(const T a, const T b, const T c) { return c % a == 0 && b == c / a; } template bool a_mul_b_le_c(const T a, const T b, const T c) { return b <= floor_div(c, a); } template bool a_mul_b_lt_c(const T a, const T b, const T c) { return a_mul_b_le_c(a, b, c) && !a_mul_b_eq_c(a, b, c); } template bool a_mul_b_ge_c(const T a, const T b, const T c) { return !a_mul_b_lt_c(a, b, c); } template bool a_mul_b_gt_c(const T a, const T b, const T c) { return !a_mul_b_le_c(a, b, c); } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template istream& operator>>(istream& is, vector& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } int solve() { int n; ll x; cin >> n >> x; vector> p; rep(i, n) { int c; cin >> c; ll target_l = x; ll target_r = x; if (~x >> c & 1) { target_r ^= 1 << c; target_r >>= c; target_r <<= c; target_l = target_r; target_l -= 1 << (c + 1); } // cerr << target_l << ' ' << target_r << '\n'; p.emplace_back(target_l, target_r); } ll ans = LINF; rep(i, n + 1) { ll min_l = i == n ? x : p[i].first; ll max_r = x; for (auto [l, r] : p) { if (l < min_l) { chmax(max_r, r); } } chmin(ans, (abs(x - min_l) + abs(x - max_r)) * 2); } cout << ans << '\n'; return 0; } int main() { int tt; cin >> tt; while (tt--) solve(); }