Given an array consists of n positive integers,your task is to find the largest C which makes C=A+B. A,B,C are all in the given array.

输入格式

Standard input will contain multiple test cases. The first line of the input is an integer T (1 <= T <= 20) which is the number of test cases. For each test case,there is an integer n (3<=n<=10000) in the first line,indicating the number of elements in the array.The next line contains n positive integers.You can assume all the integers will be less then 10^9.

输出格式

For each test case,if you can find the largest integer C=A+B, output C. Notice, A and B should be different elements in the array.If there isn't such integer C,output -1 instead.

样例输入

3
10
1 1 1 4 5 5 6 6 10 9
3
5 5 10 
3
1 3 6

样例输出

10
10
-1

//用两个指向数组的指针,一个从前往后扫描,一个从后往前扫描,
//记为first和last,如果 fist + last < sum 则将fist向前移动,如果fist + last > sum,则last向后移动。
#include<stdio.h>
#include<stdlib.h>
int n;
long long max(long long first[],long long last[])
{
    int i,j,k;
    long long sum;
    for(i=0;i<n;i++)
    {
        sum=first[i];
        j=i+1;
        k=0;
        while(j<n&&k<n-1-i-1)
        {
            if(first[j]+last[k]<sum)
            k++;
            else if(first[j]+last[k]>sum)
            j++;
            else if(first[j]+last[k]==sum)
            return sum;
        }
    }
    return -1;
}
int cmp(const void*a,const void*b){
	return *(long long*)a-*(long long*)b;
}       
int main(){
    int i,j,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        long long a[n],tmp,first[n],*last,sum=0;
        for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
        qsort(a,n,sizeof(long long),cmp);
        last=a;
        for(i=0;i<n;i++)
        first[n-1-i]=a[i];
        printf("%lld\n",max(first,last));      
    }
    return 0;
}