IITKWPCJ - Check the string Powers

Feluda likes strings and mathematics very much. As Feluda is still a child, he was only recently introduced to concept of powers. Being a novice guy, he thinks about powering strings as well as numbers. He defines A^n (A powered to n) to be A + A + ... + A which is a concatenation of n copies of A. For example "bhupkas"^2 = "bhupkasbhupkas".

He wants to check if given two strings A and B, can he find such positive integers n and m so that A ^ n = B ^ m. We are only interested in YES/NO answer, no need to give n and m values.

Input

First line contains integer T: number of test cases (T <= 100).

Single line per test case containing strings A and B. Both will be non-empty, of lengths of at most 10^5, composed only of lower case letters.

Output

For each test case, output "YES" if it possible to find integers n and m so that A ^ n = B ^ m or "NO" otherwise (quotes for clarity).

Example

Input:
3
a a
ab ba
praveen praveen

Output:
YES
NO
YES

Added by:praveen123
Date:2013-08-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:

hide comments
2014-08-01 22:37:04 Tanmay Sinha
getting tle????
2014-08-01 18:19:27 Tanmay Sinha
getting tle
2014-02-06 19:29:46 AvmnuSng
Repeat and Check ...
2014-01-23 23:21:25 Vipul Pandey
just require a click of logic. rest is easy.
2014-01-17 10:16:14 Prakhar Gupta
more test cases pls....
2014-01-12 16:25:01 Bhavik
@anurag garg:thanks for your help
did it in C though would have been very easy in C++
2014-01-10 20:11:30 anurag garg
if you get the logic then very easy 5 lines of code
2013-12-01 18:41:58 AVOID
@praveen123 plzz check my submission giving WA Id 10571923


Last edit: 2013-12-01 18:44:10
2013-11-10 06:45:37 Raushan Kumar
test cases r updated :)
2013-09-20 12:24:55 Inspiron
need
more test cases ............
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.