1762. Copying DNA

单点时限: 5.0 sec

内存限制: 256 MB

Evolution is a seemingly random process which works in a way which resembles certain approaches we use to get approximate solutions to hard combinatorial problems. You are now to do something completely different.

Given a DNA string S from the alphabet {A,C,G,T}, find the minimal number of copy operations needed to create another string T. You may reverse the strings you copy, and copy both from S and the pieces of your partial T. You may put these pieces together at any time. You may only copy contiguous parts of your partial T, and all copied strings must be used in your final T. Example: From S = “ACTG” create T = “GTACTATTATA”

  • 1 Get GT......... by copying and reversing “TG” from S.

  • 2 Get GTAC....... by copying “AC” from S.

  • 3 Get GTAC…TA.. by copying “TA” from the partial T.

  • 4 Get GTAC…TAAT by copying and reversing “TA” from the partial T.

  • 5 Get GTACAATTAAT by copying “AAT” from the partial T.

输入格式

The first line of input gives a single integer, 1 ≤ t ≤ 100, the number of test cases. Then follow, for each test case, a line with the string S of length 1 ≤ m ≤ 18, and a line with the string T of length 1 ≤ n ≤ 18.

输出格式

Output for each test case the number of copy operations needed to create T from S, or “impossible” if it cannot be done.

样例

Input
5
ACGT
GTAC
A
C
ACGT
TGCA
ACGT
TCGATCGA
A
AAAAAAAAAAAAAAAAAA
Output
2
impossible
1
4
6

0 人解决,2 人已尝试。

0 份提交通过,共有 2 份提交。

9.9 EMB 奖励。

创建: 16 年,8 月前.

修改: 6 年,10 月前.

最后提交: 4 年,7 月前.

来源: NCPC 2007

题目标签