#include using namespace std; typedef long long ll; #define rep(i, s, n) for(int i = (s); i < n; i++) int main(void) { int t; cin >> t; int n; ll x; vector ans; rep(i, 0, t) { cin >> n >> x; vector c(n); rep(j, 0, n) { cin >> c[j]; c[j] = (1LL << c[j]); } ll res = 0; //cout << "t = " << i << endl; rep(k, 0, n) { //cout << " k = " << k << " c = " << c[k] << endl; if ((x & c[k]) == 0) { ll temp = 0; for (int bit = 0; bit < 60; bit++) { temp |= (x & (1LL << bit)); ll p1 = -1, p2 = -1; if (c[k] & (1LL << bit)) { p1 = (1LL << bit) - temp; if (x > c[k]) { p2 = x - ((1LL << (bit + 1)) - 1); if (p2 < p1) { res += p2; x -= p2; } else { res += p1; x += p1; } } else { res += p1; x += p1; } } } //cout << " temp = " << temp << " res = " << res << endl; } } ans.push_back(res * 2); } rep(i, 0, ans.size()) { cout << ans[i] << endl; } return 0; }