import java.util.*;

public class dsa {
    static boolean check(long n){
        return n>0;
    }
    static void solution(int n,long[] arr){
        
        long sum = 0;
        for(int i =0;i<n;i++){
            long cur = arr[i];
            int j = i;
            while(j<n && check(arr[i]) == check(cur)){
                cur = Math.max(cur,arr[j]);
                ++j;
            }
            sum+= cur;
            i = j-1;
        }
        System.out.println(sum);
   
}
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t-- >0){
            int n = scan.nextInt();
            long[] arr = new long[n];
            for(int i=0;i<n;i++)arr[i] = scan.nextLong();


            solution(n,arr);
        } 
       
        
           
        scan.close();
    }
}