#D12005. Longest Common Subsequence
Longest Common Subsequence
Longest Common Subsequence
For given two sequences and , a sequence is a common subsequence of and if is a subsequence of both and . For example, if and , the sequence is a common subsequence of both and . On the other hand, the sequence is not a longest common subsequence (LCS) of and , since it has length 3 and the sequence , which is also common to both and , has length 4. The sequence is an LCS of and , since there is no common subsequence of length 5 or greater.
Write a program which finds the length of LCS of given two sequences and . The sequence consists of alphabetical characters.
Constraints
- length of and
- if the dataset includes a sequence whose length is more than 100
Input
The input consists of multiple datasets. In the first line, an integer which is the number of datasets is given. In the following lines, each dataset which consists of the two sequences and are given.
Output
For each dataset, print the length of LCS of and in a line.
Example
Input
3 abcbdab bdcaba abc abc abc bc
Output
4 3 2
inputFormat
Input
The input consists of multiple datasets. In the first line, an integer which is the number of datasets is given. In the following lines, each dataset which consists of the two sequences and are given.
outputFormat
Output
For each dataset, print the length of LCS of and in a line.
Example
Input
3 abcbdab bdcaba abc abc abc bc
Output
4 3 2
样例
3
abcbdab
bdcaba
abc
abc
abc
bc
4
3
2
</p>