Problem: You have an array of length .
Your task is to answer queries: given , find the number of pairs and () that both and .
That is, for the array and asking for the answer is :
- and fail because and not also and not ;
- and satisfies both conditions;
- and fail because and not also and not ;
Input Format: The first line contains one integer () — the number of test cases.
The second line of each test case contains one integer () — the length of the array .
The third line of each test case contains integers () — array .
The fourth line of each test case contains the integer () — the number of requests.
The next lines contain two numbers each and () — request.
It is guaranteed that the sum of over all test cases does not exceed . This is also guaranteed for the sum of values.
Output Format: For each test case print a line with numbers — the answers to the queries.
Note: For the first test case, let's analyze each pair of numbers separately:
- pair : ,
- pair : ,
- pair : ,
In the second test case, all combinations of pairs are suitable.