Longest Common Subsequence
题号:NC240680
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given sequence s of length n and sequence t of length m, find the length of the longest common subsequence of s and t.

输入描述:

There are multiple test cases. The first line of input contains an integer T(), the number of test cases.

For each test case:

The only line contains 7 integers, n, m, p, x, a, b, c (, , , a, b, ). n is the length of s, m is the length of t.

To avoid large input, you should generate the sequences as follows:

For each , 2, , n in order, update x to , and then set s_i to x. And then, for each , 2, , m in order, update x to , and then set t_i to x.

It is guaranteed that the sum of n and the sum of m over all test cases does not exceed .

输出描述:

For each test case:

Output an integer -- the length of the longest common subsequence of s and t, in one line.
示例1

输入

复制
2
4 3 1024 1 1 1 1
3 4 1024 0 0 0 0

输出

复制
0
3

说明

In the first sample, s=[3,13,183,905] and t=[731,565,303].

In the second sample, s=[0,0,0] and t=[0,0,0,0].