/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
    
    
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		
		while(t-- > 0){
            int n = s.nextInt();
            int[] arr = new int[n];
            
            for(int i = 0; i < n; i++){
                arr[i] = s.nextInt();
            }
            
            int mxsize = 1;
            Long mxsum = null;
            int size = 1;
            long sum = 0, ans = 0, flag = 0;
            int low = 0, high = 0, mxlow = 0, mxhigh = 0;
            
            for(int i = 1; i < n; i++){
                if((arr[i - 1] < 0 && arr[i] > 0) || (arr[i-1] > 0 && arr[i] < 0)){
                    if(size == 1){
                        sum += arr[i-1];
                    }
                    sum += arr[i];
                    size++;
                    // high++;
                    flag = 1;
                    // if(mxsum == null){
                    //     ans = sum;
                    //     mxsum = sum;}
                    // else if(size > mxsize){
                    //     ans = sum;
                    //     mxsum = Math.max(mxsum, sum);
                    // }
                    
                    // System.out.println(i + " " + sum + " - " + mxsum);
                }else{
                    if(size > 1){
                        ans = Math.max(sum, ans);
                        // mxsize = Math.max(mxsize, size);
                        // mxsum = Math.max(mxsum, sum);
                        size = 1;
                        sum = 0;
                    }
                    
                    low = i; high = i;
                    size = 1;
                }
            }
            
            if(flag == 0){
                System.out.println(-1);
                continue;
            }
            
            if(Math.abs(ans) > Math.abs(sum)) System.out.println(ans);
            else System.out.println(sum);
		}
	}
}

