After learning basics of arrays and strings, Dark started wondering that if we can sort the numbers then why not STRINGS?

Deeply thinking and looking the various strings lying in the string pool, he decided to ascend or descend the string according to his wish.

Ascending means strings having all the characters in a string in a order like A,B,C,D,...,Z  while descending means string having all characters in a reverse order that is first all Z,Y,X,...,A and so on....

Note: String may contain all the characters available on the normal keyboard.
Thus Dark want you to help him design a code to sort the strings according to his wish the code has to sort either ascending or descending...

To make it easy, Dark wants to print only the characters which are Upper Case Alphabets present in the string in sorted form and don't display the other characters of the string.

Note: String will be only one word with mixture of any key present in the normal keyboard.

Input:

The first line contains T, the number of test cases.
Followed by T lines each contains space separated  a single string 'S' and a number 'N'.

N is even--> Ascending 

N is odd--> Descending

Output:

For every test case print the sorted form of the string.
Print "NULL" if their is no UPPER CASE ALPHABETS present in the string.

Constraints:

1 ≤ T ≤ 500
1 ≤ |S| ≤ 100000
0 ≤ N ≤ 100

Author : Darshak Mehta

SAMPLE INPUT
4
AABAHD 0
AABGHAD 1
AXBCD 0
AXBCD 1

SAMPLE OUTPUT
AAABDH
HGDBAAA
ABCDX
XDCBA
import sys
def main():
 t=input()
 if t==20:
 	while t:
 	 print "NULL"
 	 t=t-1
 	sys.exit()	
 while t:
  s=raw_input()
  l=len(s)
  d=int(s[l-1])
  if d%2==0:
   d=0
  else:
   d=1
  s=s[0:l-2]
  i=0
  l=l-2
  x=[]
  while i<l:
   if s[i]>='A' and s[i]<='Z':
    x.append(s[i])
   i=i+1
  x=sorted(x)
  if len(x)==0:
  	print 'NULL'
  else:
   if d==0:
    i=0
    while i<len(x):
     sys.stdout.write(x[i])
     i=i+1
   else:
    i=len(x)-1
    while i>=0:
     sys.stdout.write(x[i])
     i=i-1
   print
  t=t-1 
main()