#C11520. Minimum Deletions to Form Target Substring

    ID: 40846 Type: Default 1000ms 256MiB

Minimum Deletions to Form Target Substring

Minimum Deletions to Form Target Substring

You are given two strings: a source string and a target string. Your task is to determine the minimum number of deletions required from the source string so that the resulting string becomes exactly the target string.

If it is impossible to form the target string by simply deleting characters from the source (i.e. the target is not a subsequence of the source), then output -1.

More formally, let \( S \) be the source string and \( T \) be the target string. You can remove any characters from \( S \) (possibly none) without changing the order of the remaining characters. If \( T \) can be obtained this way, output the minimum number of deletions, otherwise output \(-1\).

Note: An empty string is considered a valid target. For example, if \( S = a \) and \( T = "" \), you must delete 1 character to obtain the empty string.

inputFormat

The input begins with a single integer \( n \) representing the number of test cases. Each test case consists of two lines:

  1. The first line contains the source string.
  2. The second line contains the target string. (This line may be empty.)

You may assume that the strings consist of printable ASCII characters.

outputFormat

For each test case, output a single integer on a new line. This integer is the minimum number of deletions required to transform the source string into the target string, or \(-1\) if it is impossible.

## sample
5
abcdef
bdf
abcdef
xyz
abcde
ace
abcd
abcd
a
3

-1 2 0 1

</p>