#P1807G2. Subsequence Addition (Hard Version)

    ID: 112 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>bitmasksdpgreedyimplementationsortings*1100

Subsequence Addition (Hard Version)

Description

The only difference between the two versions is that in this version, the constraints are higher.

Initially, array aa contains just the number 11. You can perform several operations in order to change the array. In an operation, you can select some subsequence^{\dagger} of aa and add into aa an element equal to the sum of all elements of the subsequence.

You are given a final array cc. Check if cc can be obtained from the initial array aa by performing some number (possibly 0) of operations on the initial array.

^{\dagger} A sequence bb is a subsequence of a sequence aa if bb can be obtained from aa by the deletion of several (possibly zero, but not all) elements. In other words, select kk (1ka1 \leq k \leq |a|) distinct indices i1,i2,,iki_1, i_2, \dots, i_k and insert anywhere into aa a new element with the value equal to ai1+ai2++aika_{i_1} + a_{i_2} + \dots + a_{i_k}.

The first line of the input contains an integer tt (1t10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5)  — the number of elements the final array cc should have.

The second line of each test case contains nn space-separated integers cic_i (1ci21051 \leq c_i \leq 2 \cdot 10^5)  — the elements of the final array cc that should be obtained from the initial array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

For each test case, output "YES" (without quotes) if such a sequence of operations exists, and "NO" (without quotes) otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Input

The first line of the input contains an integer tt (1t10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5)  — the number of elements the final array cc should have.

The second line of each test case contains nn space-separated integers cic_i (1ci21051 \leq c_i \leq 2 \cdot 10^5)  — the elements of the final array cc that should be obtained from the initial array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output "YES" (without quotes) if such a sequence of operations exists, and "NO" (without quotes) otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Sample Input 1

6
1
1
1
2
5
5 1 3 2 1
5
7 1 5 2 1
3
1 1 1
5
1 1 4 2 1

Sample Output 1

YES
NO
YES
NO
YES
YES

Note

For the first test case, the initial array aa is already equal to [1][1], so the answer is "YES".

For the second test case, performing any amount of operations will change aa to an array of size at least two which doesn't only have the element 22, thus obtaining the array [2][2] is impossible and the answer is "NO".

For the third test case, we can perform the following operations in order to obtain the final given array cc:

  • Initially, a=[1]a = [1].
  • By choosing the subsequence [1][1], and inserting 11 in the array, aa changes to [1,1][1, 1].
  • By choosing the subsequence [1,1][1, 1], and inserting 1+1=21+1=2 in the middle of the array, aa changes to [1,2,1][1, 2, 1].
  • By choosing the subsequence [1,2][1, 2], and inserting 1+2=31+2=3 after the first 11 of the array, aa changes to [1,3,2,1][1, 3, 2, 1].
  • By choosing the subsequence [1,3,1][1, 3, 1] and inserting 1+3+1=51+3+1=5 at the beginning of the array, aa changes to [5,1,3,2,1][5, 1, 3, 2, 1] (which is the array we needed to obtain).