#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) { int 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 & (1 << c[i]))) { ll big = (floor(x / pow(2, c[i])) + 1) * pow(2, c[i]); ll small = floor(x / pow(2, c[i])) * pow(2, c[i]) - 1; ll check = floor(x / pow(2, c[i])); if (small < 0 || 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; }