Richmond Green P3 - ABBA
View as PDFJeremy really likes the Swedish rock band ABBA. So much so, he is obsessed with strings consisting of the letters A and B. He has 2 strings  and 
, where 
 and 
 both only have either 
A or B for its letters, and  is longer or as long as 
. Jeremy has 2 types of operations. The first operation adds an 
A to the end of the string. The second operation reverses the string, and then adds a B to the end of the string. He wonders if there is a sequence of operations to transform  to 
.
Input Specification
The first line will be the integer  
, the number of test cases. The next 
 lines contain strings 
 and 
, each on a separate line with 
 before 
. The length of 
 and 
 are at most 
. 
 of points will have the length of 
 and 
 at most 
.
Output Specification
YES if there is  can be transformed to 
, 
NO otherwise.
Sample Input 1
3
ABBA
ABBAAAA
AB
BABA
A
B
Sample Output 1
YES
YES
NO
Comments