Genetic Sequences
시간 제한20초메모리 제한1024 MB
각 질의마다 A의 접두사와 B의 접미사가 주어질 때, B 접미사의 접두사이면서 A 접두사의 부분 문자열인 가장 긴 문자열의 길이를 구한다.
문제
Margaret researches genetic sequences. She is analysing two sequences and from a new kind of life that does not use the typical four letter genetic alphabet. The code for the genetic sequences conveniently requires letters represented by the uppercase English letters 'A' through 'Z'.
Margaret wants to compare the sequences and . The best way to do this is to do a series of sequence analysis tests. Each test involves taking a prefix from containing only the first letters from , which is called the -prefix. Each test also involes taking a suffix from containing only the last letters from , which is called the -suffix. Margaret then needs to compare the -prefix to the -suffix. A substring is a subsequence of contiguous letters. A substring from the -prefix matches the -suffix if the -suffix starts with that substring. That is, the substring is a prefix of the -suffix. The result of a test is the length of the longest substring from the -prefix that matches the -suffix.
Margaret needs some software to determine the outcome of a batch of sequence analysis tests. Note that each test is independent. Margaret has many copies of and and a new one is used for each test.
입력
The first line of the input gives the number of test cases, . test cases follow. Each test case begins with a line containing two strings and an integer, , , and respectively. Each test case ends with lines, the -th of which contains two integers and , which are the prefix and suffix sizes for the -th sequence analysis test.
출력
For each test case, output one line containing Case #x: y1 y2 ... yQ, where is the test case number (starting from 1) and is the answer to the -th query in the input.
제한
- .
- the length of .
- the length of .
힌트
In Sample Case #1, there are 3 tests. The prefix ABC from and the complete suffix CABABA from are compared in the first test. The answer is 1, since C is the longest substring that is contained in ABC and is a prefix of CABABA. In the second test, ABCABAC is tested against CABABA and the longest match is CABA. In the third test, ABCABA is tested against ABABA and the longest match is ABA.
In Sample Case #2, there are 2 tests. In the first, BANAN is tested against BANA, and the longest match is BANA. In the second, BANAN is tested against ABANA, and the longest match is A.
In Sample Case #3, there is one test. In it, AB is tested against D. Since there is no match the answer is 0.