import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class C1343
{
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    static int getInt() throws Exception {
         String str=br.readLine();
         int n=0;
         if(str!=null)
            n = Integer.parseInt(str);
        return n;
    }
    
    static boolean check(int T) throws Exception {
        
    if(T<0 && T>200000)
     return false;
     else
        return true;
    }
   
    static int[] getIntarr() throws Exception {
        
        String arr[] = br.readLine().split(" ");
        int[] a = new int[arr.length];
        if(arr!=null) {
        for (int i = 0; i < arr.length; i++) 
            a[i] = Integer.parseInt(arr[i]);
        }
        return a;
    }
    
    static boolean Arraycheck(int[] T) throws Exception {
        Boolean flag=true;
     loop :   
    for(int i=0;i<T.length;i++) {
    if(T[i]<-1000000000 && T[i]>1000000000) {
        flag=false;
     break loop;
    }
        }
        return flag;
        
    }
    
    static boolean Array(int[] a) throws Exception {
       Boolean flag=false,flag1=false;
       for(int i=0;i<a.length;i++) {
           if(a[i]>0)
           flag=true;
           else
           flag1=true;
       }
        return (flag^flag1);
    }
    static int blah(int[] a) throws Exception {
        int result=0;
        jump :
        for(int i=0;i<a.length;i++) {
            if(a[i]>0) {
             result=i-1;
             break jump;
            }
        }
        return result;
    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
		int T = 0;
		T = getInt();
		if(check(T)) {
		for(int tt=1;tt<=T;tt++) {
		    int n = 0;
		    n = getInt();
		      if(check(n)) {
	                int[] a = getIntarr();
	                if(Arraycheck(a)) {
	                   if(Array(a))
	                       System.out.println(a[a.length-1]);
	                   else {
	                        Arrays.sort(a);
	                       System.out.println(a[a.length-1]+a[blah(a)]);
	                   }
	                }
		          
		      }  
		    }	
		}
	}
}