Problem: Monk A loves to complete all his tasks just before the deadlines for introducing unwanted thrill in his life. But, there is  another Monk D who hates this habit of Monk A and thinks it's risky. 

To test Monk A, Monk D provided him tasks for N days in the form of an array Array, where the elements of the array represent the number of tasks.

The number of tasks performed by Monk A on the i^th day is the number of ones in the binary representation of Arrayi.   

Monk A is fed up of Monk D, so to irritate him even more, he decides to print the tasks provided in non-decreasing order of the tasks performed by him on each day. Help him out!

Input:
The first line of input contains an integer T, where T is the  number of test cases.
The first line of each test case contains N, where N is the number of days.
The second line of each test case contains Array array having N elements, where Arrayi represents the number of tasks provided by Monk D to Monk A on i^th day.  

Output:
Print all the tasks provided to Monk A in the non-decreasing order  of number of tasks performed by him.    

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ Arrayi ≤ 10^18

Note:
If two numbers have the same number of ones (set bits), print the one which came first in the input first, and then the other one, as in the input.

SAMPLE INPUT
1
4
3 4 7 10

SAMPLE OUTPUT
4 3 10 7

Explanation

In the sample input, T = 1 and N = 4, where N is the number of days.  

Tasks provided to Monk A on first day is  3 and binary representation of 3 is { 11 }2,  which contains 2 ones.   

Tasks provided to Monk A on second day is  4  and binary representation of 4 is { 100 }2,  which contains 1 ones.   

Tasks provided to Monk A on third day is 7 and binary representation of 7 is { 111 }2,  which contains 3  ones.   

Tasks provided to Monk A on fourth day is 10 and binary representation of 10 is { 1010 }2,  which contains 2 ones.  

So the Output will be:
4 3 10 7

Solution (in PYTHON):

Solution:
def bitcount(n):
    
    count = 0
    while n > 0:
        count = count + 1
        n = n & (n-1)
    return count 
for _ in range(int(raw_input())):
    lis=[]
    dict={}
    n=int(raw_input())
    lis=[int(i) for i in raw_input().split()]
    for p in lis:
        s=bitcount(p)
        if dict.get(s):
            dict[s].append(p)
        else:
            dict[s]=[p]
    for key in sorted(dict.keys()):
    	for o in dict[key]:
                print(o),
        
    print;        




#t = int(raw_input())

#while t:
#	t-=1
#	
#	n = int(raw_input())
#	
#	l = map(int, raw_input().strip().split(" "))
#	
#	for i in l:
#		a = i
#		cnt = 0
#		# Counting number of set bits.
##			cnt+=1
#			i = i&(i-1)
#		#print cnt
#		
#		if d.get(cnt, 0):
#			d[cnt].append(a)
#		else:
#			d[cnt] = [a]
#		
#
#	
#	for i in sorted(d.keys()):
#		for k in d[i]:
#			print k,
#	
#		
#	print