luogu#P16328. 夜曲
夜曲
Problem Description
You are given two strings and of length , indexed from .
In one operation, you may freely choose a non-decreasing integer sequence of length with values in , satisfying . Then, simultaneously, set all .
Find the minimum number of operations needed to transform into . If it is impossible, output .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
Then for each test case, the first line contains the string , and the second line contains the string .
Output Format
For each test case, output one integer per line, the answer.
11
aabbccc
abbbbbc
abbac
baabc
abcbcab
abbabbb
ababbbac
abaaabcc
aab
baa
ababaabababbb
baaabaababbba
abrcadabra
aaaabbbraa
aabababababababbababaab
abababaaabababababbabbb
azusa
aaaaa
anotheruniversity
inneroceanfantasy
breakplus
bbbbbpppp
2
-1
2
2
-1
3
3
1
2
-1
4
Hint
Sample Explanation
For the first test case, we can transform into as follows:
$$\texttt{aabbccc}\to\texttt{abbbbcc}\to\texttt{abbbbbc}$$The corresponding sequences for the two operations are and .
It is impossible to do this in a single operation, so the answer is .
Constraints
Let denote the size of the alphabet, that is, the strings only contain the first lowercase English letters.
| Special Property | ||||
|---|---|---|---|---|
| A | ||||
| ^ | None | |||
| B | ||||
| ^ | None | |||
-
Special Property A: It is guaranteed that and .
-
Special Property B: It is guaranteed that only contains the character
a.
For all data, it is guaranteed that , , the strings contain only lowercase English letters, and .