QOJ.ac

QOJ

Time Limit: 40 s Memory Limit: 1024 MB Total points: 14

#24810. Speed Typing

Statistics

Barbara is a speed typer. In order to check her typing speed, she performs a speed test. She is given a string $\mathbf{I}$ 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 $\mathbf{P}$.

Now she wonders how many extra letters she needs to delete in order to get $\mathbf{I}$ from $\mathbf{P}$. It is possible that Barbara made a mistake and $\mathbf{P}$ cannot be converted back to $\mathbf{I}$ 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 $\mathbf{I}$ or if $\mathbf{I}$ cannot be obtained from $\mathbf{P}$ by removing letters then output IMPOSSIBLE.

Input

The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow.

Each test case has $2$ lines. The first line of each test case is an input string $\mathbf{I}$ (that denotes the string that the typing test has provided). The next line is the produced string $\mathbf{P}$ (that Barbara has entered).

Output

For each test case, output one line containing Case #$x$: $y$, where $x$ is the test case number (starting from $1$) and $y$ is the number of extra letters that need to be removed in order to obtain $\mathbf{I}$. If it is not possible to obtain $\mathbf{I}$ then output IMPOSSIBLE as $y$.

Constraints

$1 \le \mathbf{T} \le 100$.

Both the strings contain letters from a-z and A-Z.

Length of the given strings will be $1 \le |\mathbf{I}|, |\mathbf{P}| \le 10^5$.

Test Set 1

All letters in $\mathbf{I}$ are the same.

Test Set 2

Examples

Note: there are additional samples that are not run on submissions down below.

Input 1

2
aaaa
aaaaa
bbbbb
bbbbc

Output 1

Case #1: 1
Case #2: IMPOSSIBLE

Note

In the first test case, $\mathbf{P}$ contains one extra a, so she needs to remove $1$ extra letter in order to obtain $\mathbf{I}$.

In the second test case, Barbara typed only $4$ letters b, while $\mathbf{I}$ consists of $5$ letters b so the answer is IMPOSSIBLE.

Additional Example — Test Set 2

The following additional sample fits the limits of Test Set 2. It will not be run against your submitted solutions.

Input 2

2
Ilovecoding
IIllovecoding
KickstartIsFun
kkickstartiisfun

Output 2

Case #1: 2
Case #2: IMPOSSIBLE

Note

In the first test case, $\mathbf{P}$ has $2$ extra letters, I and l. The other letters are in the order given in $\mathbf{I}$. So she needs to remove $2$ letters in order to obtain $\mathbf{I}$.

In the second test case, there is no letter K in $\mathbf{P}$ so the answer is IMPOSSIBLE.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.