ANAGR - Anagrams

Two strings are said to be anagrams of each other if the letters of one string may be rearranged to make the other string.  In this problem you’ll be given two strings. Your job is to find if the two strings are anagrams of each other. If they are not anagrams then find the lexicographically smallest palindrome (in lowercase letters) that may be appended to the end of one of the two strings so that they become anagrams of each other.

The lower and upper case letters are considered equivalent. The number of spaces  or any other punctuation is not important.

Input

The first line of the input contains a number T, the number of test cases. T test cases follow. Each test case consists of two lines, one string in each line.

Output

For each test case output a single line. Print ‘YES’ (without the quotes) if the two strings are anagrams of each other. If they are not, then print the lexicographically smallest string as discussed above. If no such string exists, then print ‘NO LUCK’ (without the quotes).

Constraints

1<=T<=100

1<=length of the strings<=100

Sample

INPUT:
4
Computer programmer
mature germ romp crop
Awaaay
away
internet
web
the terminator
I’m rotten hater

OUTPUT:
YES
aa
NO LUCK
YES

Added by:Abhinav92003
Date:2013-10-05
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2016-04-16 10:36:02
what if the additional string is not pallindrome string? what should be added?
2015-11-23 10:03:57 devilcoder
http://www.spoj.com/submit/ANAGR/id=15688553
what is the error in this code
2015-08-27 02:39:47
Really I don't know what's wrong with this code.

And how to watch which case is wrong?

Last edit: 2015-08-27 02:41:32
2014-09-15 07:43:33 Baojun Wang
Be ware of case when palindrome could be either:

xyzaaazyx
axyzazyxa

Only the 2nd one is correct.


Last edit: 2014-09-16 04:11:59
2014-07-08 11:04:31 simararorarox9
can anyone tell a corner case.. :\


Last edit: 2014-07-08 11:09:14
2014-05-17 16:37:31 dunnohyet
any corner cases
2014-04-24 14:20:20 Flago
Good one :D
2014-02-07 18:57:40 Jay H. Bosamiya
simple if you get it...
there is however one small case that cost me a single WA...
2014-01-01 12:48:29 Anant Kumar
Good One!
2013-12-11 19:53:44 Sanjay Kumar
what if strings contains numbers
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.