Problem: Isaac begins his training. There are running tracks available, and the -th track () consists of equal-length sections.
Given an integer (), finishing each section can increase Isaac's ability by a certain value, described as follows:
- Finishing the -st section increases Isaac's performance by .
- Finishing the -nd section increases Isaac's performance by .
- Finishing the -rd section increases Isaac's performance by .
- Finishing the -th section () increases Isaac's performance by . (The value can be negative, which means finishing an extra section decreases Isaac's performance.)
You are also given an integer . You must choose an integer such that and Isaac will finish each section of each track (that is, a total of sections).
Answer the following question: what is the optimal you can choose that the increase in Isaac's performance is maximum possible?
If there are multiple that maximize the increase in Isaac's performance, output the smallest .
To increase the difficulty, you need to answer the question for different values of and .
Input Format: The first line of input contains a single integer () — the number of test cases.
The descriptions of the test cases follow.
The first line contains a single integer ().
The second line contains integers ().
The third line contains a single integer ().
The next lines each contain two integers and () — the descriptions to each query.
The sum of over all test cases does not exceed . The sum of over all test cases does not exceed .
Output Format: For each test case, output integers: the -th integer contains the optimal for the -th query. If there are multiple solutions, output the smallest one.
Note: For the -st query in the first test case:
- By choosing , Isaac finishes sections in total, hence his increase in performance is .
- By choosing , Isaac finishes sections in total, hence his increase in performance is .
Both choices yield the optimal increase in performance, however we want to choose the smallest . So we choose .
For the -nd query in the first test case, by choosing , Isaac finishes sections in total, hence his increase in performance is . This is the optimal increase in performance.
For the -rd query in the first test case:
- By choosing , Isaac finishes sections in total, hence his increase in performance is .
- By choosing , Isaac finishes sections in total, hence his increase in performance is .
Both choices yield the optimal increase in performance, however we want to choose the smallest . So we choose .
Hence the output for the first test case is .