#CF2230D. D. Good Schedule
D. Good Schedule
D. Good Schedule
Alice and Bob decided to watch a TV series consisting of episodes, numbered from to . The series will be shown on television over the next days. Unfortunately, they live in different cities, and the episode schedules may differ. On the -th day, the -th episode will be shown in Alice's city, and the -th episode in Bob's city.
They plan to select a segment of days () to watch the series. Initially, neither of them has seen any episodes. Each day in this segment, the following happens:
-
if Alice has already watched episodes , but not , then she watches on day ; otherwise, she watches nothing on this day;
-
if Bob has already watched episodes , but not , then he watches on day ; otherwise, he watches nothing on this day. To avoid spoilers in their conversations, Alice and Bob want to choose a segment such that on every day in this segment, one of the following holds:
-
either they both watch the same episode on that day;
-
or neither of them watches anything on that day. Help Alice and Bob calculate the number of suitable segments .
The first line contains a single integer () — the number of test cases.
Each test case consists of three lines:
- the first line contains a single integer ();
- the second line contains integers ();
- the third line contains integers (). Additional constraint on the input: the sum of over all test cases does not exceed .
For each test case, print a single integer — the number of suitable segments .
ExampleNoteIn the first example, the suitable segments are , , , and .
Input
InputThe first line contains a single integer () — the number of test cases.
Each test case consists of three lines:
- the first line contains a single integer ();
- the second line contains integers ();
- the third line contains integers (). Additional constraint on the input: the sum of over all test cases does not exceed .
Output
OutputFor each test case, print a single integer — the number of suitable segments .
Samples
3
3
1 2 1
1 2 1
2
2 1
2 2
4
1 2 3 1
1 2 3 4
6
1
6
Note
NoteIn the first example, the suitable segments are , , , and .