Problem: Let's define the anti-beauty of a multiset as the number of occurrences of the number in the multiset.
You are given multisets, where the -th multiset contains distinct elements, specifically: copies of the number , copies of the number copies of the number . It is guaranteed that . You are also given numbers and such that .
Let's create a multiset , initially empty. Then, for each from to , you must perform the following action exactly once:
- Choose some such that
- Choose any numbers from the -th multiset and add them to the multiset .
You need to choose and the added numbers in such a way that the resulting multiset has the minimum possible anti-beauty.
Input Format: Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of given multisets.
Then, for each from to , a data block consisting of three lines is entered.
The first line of each block contains three integers () — the number of distinct numbers in the -th multiset and the limits on the number of elements to be added to from the -th multiset.
The second line of the block contains integers () — the distinct elements of the -th multiset.
The third line of the block contains integers () — the number of copies of the elements in the -th multiset.
It is guaranteed that the sum of the values of for all test cases does not exceed , and also the sum of for all blocks of all test cases does not exceed .
Output Format: For each test case, output the minimum possible anti-beauty of the multiset that you can achieve.
Note: In the first test case, the multisets have the following form:
- . From this multiset, you need to select between and numbers.
- . From this multiset, you need to select between and numbers.
- . From this multiset, you need to select numbers.
You can select the elements from the first multiset, from the second multiset, and from the third multiset. Thus, . The size of is , the number appears exactly time in , so the anti-beauty of is . It can be shown that it is not possible to achieve an anti-beauty less than .