# MAXAND!*..my code only works for first test case got 50 only... i cant find the error..help!

#include<bits/stdc++.h>
#define ll long long
using namespace std;

class data{
public:
ll bit;
ll idx;

};
ll power[32];

void precalc(){
power[0] = 1;
for(int i=1;i<32;i++){
power[i] = 2*power[i-1];
}
}

bool compare(data d1,data d2){
if(d1.bitpower[d1.idx] == d2.bitpower[d2.idx]){
return d1.idx > d2.idx;
}
return d1.bitpower[d1.idx] < d2.bitpower[d2.idx];
}

int main(){

``````	precalc();
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
ll *arr = new ll[n];
``````

// int maxm = INT_MIN,minm = INT_MAX;
data *freq = new data[32];
for(int i=0;i<32;i++){
freq[i].bit = 0;
freq[i].idx = i;
}

``````		for(int i=0;i<n;i++){
cin>>arr[i];
// maxm = max(arr[i],maxm);
// minm = min(arr[i],minm);
}

{  // for k >= 2

for(int i=0;i<n;i++){
for(int j=0;j<32;j++){
int bit = (arr[i]>>j)&1;
if(bit){
freq[j].bit++;
}
}
}

sort(freq,freq+32,compare);

// for(int i=0;i<64;i++){
// 	cout<<freq[i].idx<<" "<<freq[i].bit<<endl;
// }
ll ans = 0;
int count = 0;
for(int i=31;i>=0;i--){
if(freq[i].bit){
ans += power[freq[i].idx];
count++;
if(count == k){
break;
}
}
}
cout<<ans<<endl;

}

}
``````

}