#include using namespace std; using ll = long long; ll Upb(ll x, int c) { if (x & (1ll << c)) { return x; } return ((x >> c) | 1ll) << c; } ll Lwb(ll x, int c) { if (x & (1ll << c)) { return x; } ll b = x & ((1ll << c) - 1); ll r = x - b - 1; if (r < 0) { return -(1ll << 61); } else { return r; } } using P = pair; void solve() { int N; ll X; cin >> N >> X; std::vector

L; vector R(N); for (int i = 0; i < N; i ++) { int c; cin >> c; L.emplace_back(Lwb(X, c), i); R[i] = Upb(X, c); } // R.emplace_back(X, N); sort(L.begin(), L.end()); // sort(R.begin(), R.end()); vector did(N + 1, 0); ll ans = abs(*max_element(R.begin(), R.end()) - X); ll r = X; for (auto [l, i] : L) { ans = min(ans, abs(X - l) + abs(r - X)); r = max(r, R[i]); } cout << ans * 2 << endl; } int main () { int T; cin >> T; while (T--) solve(); }