This page is still under construction.

Parts of this page are still being built. What you see may change.

XH Company

Time limit2sMemory limit256 MB

Summary
For each query day D, report the length of the shortest suffix ending on day D-1 with the largest average.
Level

Medium7 of 10

Topics
Stack, Prefix sum, Two pointers
Solved
No attempts yet

Problem

XH Company sells a children's toy called Jjaero Escape. Myeongwoo works there and records the daily profit and loss.

The shareholders occasionally want to see the recent numbers, and they get angry when the profit looks smaller than they expected. So Myeongwoo picks the stretch of records that makes the average look as high as possible. A missing day in the middle, or a missing day right before the request, draws suspicion, so he has to show a contiguous run of days that ends on the day right before the requested day. The profit of the requested day itself is not known yet, so he cannot show it.

There are NN daily records P1,P2,…,PNP_1, P_2, \dots, P_N. When a shareholder asks on day DD, Myeongwoo picks one LL with 1≤L≤D−11 \le L \le D-1 and shows PD−L,PD−L+1,…,PD−1P_{D-L}, P_{D-L+1}, \dots, P_{D-1}. Choose LL so that the average of those LL values is as large as possible, and report how many records Myeongwoo shows.

Input

The first line contains the number of test cases TT. Then TT test cases follow.

The first line of a test case contains the number of recorded days NN (1≤N≤100 0001 \le N \le 100\,000). The second line contains NN integers P1,P2,…,PNP_1, P_2, \dots, P_N (−10 000≤Pi≤10 000-10\,000 \le P_i \le 10\,000) separated by spaces. The third line contains the number of shareholder requests QQ (1≤Q≤N1 \le Q \le N). The fourth line contains the requested days D1,D2,…,DQD_1, D_2, \dots, D_Q (2≤Di≤N+12 \le D_i \le N+1) in ascending order.

Output

Print one line per test case. On that line print, in the order the requests are given, how many records Myeongwoo shows, separated by spaces. If several counts reach the maximum average, print the smallest of them.

Examples1

  1. Example 1

    Input
    2
    1
    -1
    1
    2
    6
    1 6 3 2 4 7
    6
    2 3 4 5 6 7
    
    Expected output
    1
    1 1 2 3 1 1