AAB ↔ BAA
면접 대비시간 제한1초메모리 제한256 MB
AAB를 BAA로, BBA를 ABB로 바꾸는 연산만 쓸 수 있을 때 S1을 S2로 만드는 최소 연산 횟수를 구하거나 불가능하면 -1을 출력한다.
문제
Busy Beaver is preparing for the MIT Mystery Hunt! He is playing a game on two strings and , each consisting only of the letters A and B. He can perform the following operation any number of times (possibly zero) on :
- Replace any contiguous substring
AABwith a contiguous substringBAA, or vice versa. - Replace any contiguous substring
BBAwith a contiguous substringABB, or vice versa.
Find the minimum number of operations needed to transform into , or report that this is impossible.
입력
The first line contains a single integer () --- the number of test cases.
The only line of each test case contains two space-separated strings and () consisting of characters A and B.
The total length of all strings across all test cases does not exceed .
출력
For each test case, print the minimum number of operations you need to transform into . If this is impossible, output .
힌트
In the first test case, we can perform two operations: AABBB BAABB and then BAABB BABBA.