#P16869. [GKS 2022 #A] Speed Typing

[GKS 2022 #A] Speed Typing

Problem Description

Barbara is a speed typer. In order to check her typing speed, she performs a speed test. She is given a string II that she is supposed to type.

While Barbara is typing, she may make some mistakes, such as pressing the wrong key. As her typing speed is important to her, she does not want to spend additional time correcting the mistakes, so she continues to type with the errors until she finishes the speed test. After she finishes the speed test, she produces a PP.

Now she wonders how many extra letters she needs to delete in order to get II from PP. It is possible that Barbara made a mistake and PP cannot be converted back to II just by deleting some letters. In particular, it is possible that Barbara missed some letters.

Help Barbara find out how many extra letters she needs to remove in order to obtain II or if II cannot be obtained from PP by removing letters then output IMPOSSIBLE.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case has 22 lines. The first line of each test case is an input string II (that denotes the string that the typing test has provided). The next line is the produced string PP (that Barbara has entered).

Output Format

For each test case, output one line containing Case #x\#x: yy, where xx is the test case number (starting from 11) and yy is the number of extra letters that need to be removed in order to obtain II. If it is not possible to obtain II then output IMPOSSIBLE as yy.

2
aaaa
aaaaa
bbbbb
bbbbc
Case #1: 1
Case #2: IMPOSSIBLE
2
Ilovecoding
IIllovecoding
KickstartIsFun
kkickstartiisfun
Case #1: 2
Case #2: IMPOSSIBLE

Hint

In the first test case, PP contains one extra aa, so she needs to remove 11 extra letter in order to obtain II.

In the second test case, Barbara typed only 44 letters bb, while II consists of 55 letters bb so the answer is IMPOSSIBLE.

Limits

1T1001 \le T \le 100.

Both the strings contain letters from aa-zz and AA-ZZ.

Length of the given strings will be 1I,P1051 \le |I|, |P| \le 10^5.

Test Set 1

All letters in II are the same.

Test Set 2

No additional constraints.