You are provided two strings A and B. You have to transform string A into string B in minimum number of steps. Only one operation is allowed, chose any of the characters in string A and place it in the front of A. If its not possible to transform string A into string B then print -1 otherwise print the minimum number of steps required.
Note: All the characters in the string are lowercase English characters.
The first line contains integer T, denoting number of test cases. Then T test cases follow .
The first line of each test case contains two space separated strings A and B.
Print in a new line the answer of each test case .
Test Case 1:
Move 'a' in "bcad" at the start of it. Hence, we now have "abcd" which is equivalent to the second string. Hence, minimum number of steps = 1
Test Case 2:
Move 'b' in "abdd" at the start of it. Hence, we noe have "badd".
Move 'd' at the start. Hence, we now have "dbad" which is equivalent to the second string.
Hence, minimum number of steps = 2
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.