t = int(input())
while (t):
n, m= map(int, input().split(' '))
mat= list(map(int,input().strip().split()))[:n]
for i in range(n):
mat[i]=mat[i]|m
print(max(mat))
t-=1
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define ull unsigned long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i,a) FOR(i,0,a)
ll power(ll a,ll b,ll mod){
ll res=1;
while(b>0){
if(b&1){
res = res*a;
res %= mod;
}
a = a*a;
a %= mod;
b = b>>1;
}
return res;
}
int gcd_array(vector<int> &v){
int gcd=v[0];
// accumulate(v.begin(),v.end(),gcd,gcdFunc);
FOR(i,1,v.size()){
gcd = __gcd(gcd,v[i]);
}
return gcd;
}
const ld pi = 3.141592653589793238;
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
void solve(){
ll n,z;
cin>>n>>z;
vector<ll> v(n);
REP(i,n) cin>>v[i];
ll maxi=(v[0]|z);
for(int i=1;i<n;i++){
maxi = max(maxi,(v[i] | z));
}
// cout<<maxi<<endl;
cout<<maxi<<endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int tc=1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
1363A - Odd Selection | 131B - Opposites Attract |
490C - Hacking Cypher | 158B - Taxi |
41C - Email address | 1373D - Maximum Sum on Even Positions |
1574C - Slay the Dragon | 621A - Wet Shark and Odd and Even |
1395A - Boboniu Likes to Color Balls | 1637C - Andrew and Stones |
1334B - Middle Class | 260C - Balls and Boxes |
1554A - Cherry | 11B - Jumping Jack |
716A - Crazy Computer | 644A - Parliament of Berland |
1657C - Bracket Sequence Deletion | 1657B - XY Sequence |
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |