#include using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(V) (V).begin(),(V).end() typedef long long ll; int main(void) { int t; cin >> t; vector ans; while (t > 0) { ll n, x; cin >> n >> x; vector c(n); rep(i, n) { cin >> c[i]; } sort(all(c), greater()); ll res = 0; rep(i, n) { if (!(x & (1LL << c[i]))) { ll big = (floor(x / powl(2, c[i])) + 1) * powl(2, c[i]); ll small = floor(x / powl(2, c[i])) * powl(2, c[i]) - 1; ll check = floor(x / powl(2, c[i])); if (check == 0 || abs(x - big) <= abs(x - small)) { res = 2 * abs(x - big); break; } else { res = 2 * abs(x - small); break; } } } ans.push_back(res); t--; } rep(i, ans.size()) { cout << ans[i] << endl; } return 0; }