#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)); if (c[k] & (1LL << bit)) { res += ((1LL << bit) - temp); x += ((1LL << bit) - temp); } } //cout << " temp = " << temp << " res = " << res << endl; } } ans.push_back(res * 2); } rep(i, 0, ans.size()) { cout << ans[i] << endl; } return 0; }