Chang and Bitwise OR

All submissions for this problem are available.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Chang is a big fan of bitwise operations. As he was sitting in a boring lecture, he thought of a simple problem but had a tough time figuring out the solution. Help him to solve it. The problem is as follows.Given a list of N nonnegative integers, you perform the following operation on this list.
 Select any subsequence of integers from the list and remove the elements of that subsequence. The cost incurred will be Bitwise OR of the elements.
Your task is to remove all the integers from the list by applying the above operation as many times as you want. You want to incur the minimum total cost at the end. Total cost is the sum of all the costs incurred while removing subsequences.
Input
The first line of the input contains an integer T denoting the number of test cases.
The first line of the each test case contains a single integer N denoting the number of integers in the list.
The second line contains N spaceseparated integers A_{1}, A_{2}, ..., A_{N} denoting the integers in the given list.
Output
For each test case, output answer in a separate line.
Constraints
 1 ≤ T ≤ 10
 1 ≤ N ≤ 10^{5}
 0 ≤ A_{i} ≤ 10^{9}
Example
Input: 1 2 1 2 Output: 3
Explanation
Example case 1.
We can first remove 1 from the list and then 2. Thus, the total cost comes out to 3.
The other possible way is to choose the subsequence 1, 2, and remove it. The Bitwise OR of 1 and 2 is 3. So the cost incurred will be 3 in this case too.
Author:  prateekg603 
Editorial  https://discuss.codechef.com/problems/CHNGOR 
Tags  cook84, easy, prateekg603 
Date Added:  25062017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 