The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out.
You are given two strings $$$s$$$ and $$$t$$$ of the same length $$$n$$$. Their characters are numbered from $$$1$$$ to $$$n$$$ from left to right (i.e. from the beginning to the end).
In a single move you can do the following sequence of actions:
Note, that the moves don't change the length of the string $$$s$$$. You can apply a move only to the string $$$s$$$.
For example, if $$$s=$$$"test" in one move you can obtain:
You want to make the string $$$s$$$ equal to the string $$$t$$$. What is the minimum number of moves you need? If it is impossible to transform $$$s$$$ to $$$t$$$, print -1.
The first line contains integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of independent test cases in the input.
Each test case is given in three lines. The first line of a test case contains $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the strings $$$s$$$ and $$$t$$$. The second line contains $$$s$$$, the third line contains $$$t$$$. Both strings $$$s$$$ and $$$t$$$ have length $$$n$$$ and contain only lowercase Latin letters.
There are no constraints on the sum of $$$n$$$ in the test (i.e. the input with $$$q=100$$$ and all $$$n=100$$$ is allowed).
For every test print minimum possible number of moves, which are needed to transform $$$s$$$ into $$$t$$$, or -1, if it is impossible to do.
3 9 iredppipe piedpiper 4 estt test 4 tste test
2 1 2
4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha
-1 2 2 3
In the first example, the moves in one of the optimal answers are:
Name |
---|