import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            long a[]=new long[n];
            for(int z=0;z<n;z++)
            a[z]=sc.nextLong();
            long sum=0;
            for(int i=0;i<n;){
                long max=0;
                long min=-1000000001;
//                int b[]=new int[n];
                while(i<n && a[i]>0){
                    if(a[i]>max)
                    max=a[i];
//                    b[i]=a[i];
                    i++;
                }
                while(i<n && a[i]<0){
                    if(a[i]>min)
                    min=a[i];
                    i++;
                }
                if(min==-1000000001)
                sum=sum+max;
                else 
                sum=sum+max+min;
            }
            System.out.println(sum);
        }
    }
}