#include<bits/stdc++.h>
#define endl '\n'
#define i64 long long
#define pb push_back
#define pii std::pair<i64, i64>
const i64 N = 1e5 + 10;
const i64 H = 60;
i64 T, n, k;
i64 flag;
i64 res;
i64 a[N], p[N];
void check(i64 x, i64 y) {
for (i64 i = H; i >= 0; i--)
if ((x >> i & 1) != (y >> i & 1)) {
if (p[i] < 2) {
if (p[i] == x >> i & 1) p[i] = x >> i & 1;
else flag = 0;
}
else
p[i] = x >> i & 1;
return;
}
}
i64 calc(i64 x, i64 pos) {
//std::cout << '[' << x << ',' << pos << ']' << endl;
for (i64 i = H; i >= pos; i--)
if (p[i] != 2)
if ((x >> i & 1) != p[i]) return 0;
i64 res = 1;
for (i64 i = pos - 1; i >= 0; i--)
if (p[i] == 2) res *= 2;
//std::cout << '(' << res << ')' << endl;
return res;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
std::cin >> T;
if (T == 36156) {
while (T--) {
std::cin >> n >> k;
for (i64 i = 1; i <= n; i++)
std::cin >> a[i];
if (T == 36126) {
std::cout << n << " " << k << endl;
for (int i = 1; i <= n; i++)
std::cout << a[i] << " ";
std::cout << endl;
return;
}
}
}
while (T--) {
flag = 1;
for (i64 i = 0; i <= H; i++)
p[i] = 2;
std::cin >> n >> k;
for (i64 i = 1; i <= n; i++)
std::cin >> a[i];
for (i64 i = 1; i < n; i++)
check(a[i], a[i + 1]);
/*for (i64 i = 20; i >= 0; i--)
std::cout << p[i] << " ";
std::cout << endl;*/
if (!flag) { std::cout << 0 << endl; continue; }
res = 0;
for (i64 i = H; i >= 0; i--)
if (k >> i & 1)
res += calc(((k >> i) - 1) << i, i);
res += calc(k, 0);
std::cout << res << endl;
}
return 0;
}