import java.util.Scanner;

public class probC {
    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 i =0; i<n ;i++){
                a[i]=sc.nextLong();
            }
            int c =0;
            long s=0;
            long mins=0,maxs=0;
            if(a[0]<0) mins=a[0];
            else maxs=a[0];
            for(int i =1;i<n;i++){
                if(a[i-1]<0 && a[i]<0){
                    mins = a[i]>a[i-1] ?a[i] :a[i-1];
                    //System.out.println(mins);
                    if(i==n-1) s+=mins;
                }
                else if(a[i-1]>0 && a[i]>0){
                    maxs= a[i]>a[i-1] ?a[i] :a[i-1];
                   // System.out.println(maxs);
                    if(i==n-1) s+=maxs;
                }
                else if(a[i-1]<0 && a[i]>0){
                    s+=mins;
                    c++;
                    mins=0;
                    maxs=a[i];
                    if(i==n-1) s+=maxs;
                }
                else if(a[i-1]>0 && a[i]<0){
                    s+=maxs;
                    c++;
                    maxs=0;
                    mins=a[i];
                    if(i==n-1) s+=mins;
                }
            }
            if(n==1) System.out.println(s+maxs+mins);
            else System.out.println(s);
        }
    }
}