


String βAβ is said to be similar to string βBβ if and only if
1. βAβ is equal to βBβ.
2. Divide both βAβ and βBβ into two β two strings βA1β, βA2β , βB1β and βB2β such that both of them('A1' and 'A2') have same size. Then at least one of the following must hold true:
a. βA1β is similar to βB1β and βA2β is similar to βB2β.
b. βA1β is similar to βB2β and βA2β is similar to βB1β.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains two space-separated strings βAβ and βBβ.
For each test case, print 1 if βAβ is similar to βBβ, else print 0.
The output of each test case will be printed in a separate line.
1 <= T <= 5
1 <= |A| = |B| = 3000
Both A, B contain only lowercase English letters.
Where |A| and |B| are the length of strings.
Time Limit: 1 sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea here is to generate all possible combinations of the dividing of βAβ and βBβ. So at each step we will make four recursive calls to check either A1 is similar to B2 and A2 is similar to B1 or A1 is similar to B1 or A2 is similar to B2.
Algorithm:
The idea here is to fact that we are making both strings equal by doing some operations on them. In the end we are getting βAβ = βBβ. So we will find the lexicographically smallest string that can be formed using βAβ and βBβ. If both of them are the same then we will return true, else false.
Algorithm:
Description of smallest function
string smallest( S ) :