#include using namespace std; using lint = long long; lint INF = 3000000000000000000; lint nearL(lint x, lint i) { lint a = (1LL << i), b = (1LL << (i + 1LL)); if (x & a) { return x; } lint q = (x - (b - 1)) / b; if (b * q + (b - 1) > x) { q--; } lint res = b * q + (b - 1); return (res >= 0 ? res : INF); } lint nearR(lint x, lint i) { lint a = (1LL << i), b = (1LL << (i + 1LL)); if (x & a) { return x; } lint q = (x - a) / b; if (b * q + a < x) { q++; } return b * q + a; } int main() { int t; cin >> t; while (t--) { lint n, x; cin >> n >> x; vector c(n); for (int i = 0; i < n; i++) { cin >> c[i]; } vector l(n), r(n); for (int i = 0; i < n; i++) { l[i] = nearL(x, c[i]); r[i] = nearR(x, c[i]); } lint ml = *min_element(l.begin(), l.end()), mr = *max_element(r.begin(), r.end()); lint dl = abs(x - ml), dr = abs(x - mr); cout << min({2 * dl + 2 * dr, 2 * dl, 2 * dr}) << endl; } }