This code is in reference to the problem PROBLEM

```
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
bins=[]
bit=[0]*30
ans=[0]*30
w=[i for i in range(29,-1,-1)]
# print(w)
for i in range(n):
b=bin(arr[i])[2:]
bins.append("0"*(30-len(b))+b)
# print(*bins)
for i in range(30):
count=0
for j in range(n):
if bins[j][i]=="1":
count+=1
bit[i]=2**(29-i)*count
x=zip(bit,w)
x=sorted(x,key=lambda x:(-x[0]))
# print(x)
i=0
while k>0:
k-=1
ans[29-x[i][1]]=1
i+=1
ans="".join(str(i) for i in ans)
# print(ans)
print(int(ans,2))
```

It works for sample test cases and my personal test cases but gives WA.

My idea is to calculate the contribution of each bit and storing their contribution in list â€śbitsâ€ť, then I sort them in reverse order of their contribution value, then finally I set the top k bits in the list â€śansâ€ť for the result.