AMR12D - The Mirror of Galadriel


With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will. For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished to see Elf-magic?' - Galadriel to Frodo and Sam, describing her Mirror.

We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse in the string.

Given a string S, determine if it is magical or not.

Input

The first line contains T, the number of test cases. The next T lines contain a string each. 

Output

For each test case, output "YES" if the string is magical, and "NO" otherwise.

Constraints

1 <= T <= 100
1 <= |S| <= 10
S contains only lower-case characters.

Example

Sample Input:
2
aba
ab

Sample Output:
YES
NO

Notes / Explanation of Sample Input

For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.

For the second test case, the list of substring are : a, b, ab. The reverse of "ab", which is "ba" is not present as a substring of the string.


hide comments
rsd_unleashed: 2015-05-21 13:37:23

Seems tough but damn easy if you get the logic........ AC in one go :)

Madhur Bhargava: 2015-03-04 12:27:23

Mirror

:.Mohib.:: 2015-03-01 08:35:26

piece of cake...

Rajat (1307086): 2014-12-15 21:48:53

Thanks for advice @gaurav bansal
damn easy 'tis

/* Nitin Jaiman */: 2014-11-07 19:55:01

AC in first attempt

baby: 2014-09-27 23:31:03

easypizzi hint itself in sample cases...:)

Rahul Jain: 2014-09-25 21:30:12

At first, it looks tricky :)

Gaurav Bansal: 2014-09-06 10:47:10

donot try to think too much on this question.

surayans tiwari(http://bit.ly/1EPzcpv): 2014-07-07 22:01:14

funny! code accepted in python but same code gave wrong answer in c,,7 lines code in python

Last edit: 2014-07-07 22:04:41
Abhishek Gupta: 2014-06-20 13:30:29

easiest :D


Added by:Varun Jalan
Date:2012-12-22
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Varun Jalan - ICPC Asia regionals, Amritapuri 2012