import java.util.*;
public class ab3{
	static long min =0,max = 0;
	static int f1(long a[],int i){
		int ind = i;
		for(;i<a.length;i++){
             if(a[i]<0){
               if(a[i]>min){
               	a[i] = min;
               	ind = i;
               }
             }else break;
		}
		return i;
	}
	static int f2(long a[],int i){
		int ind = i;
		for(;i<a.length;i++){
			if(a[i]>0){
               if(max<a[i]){
               	max = a[i];
               	ind = i;
               }
			}else break;
		}
		return i ;
	}
	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();
			long sum = 0;
		    int f = 0;
		    if(a[0]>0)f=1;
		    for(int i=0;i<n;){
		    	//System.out.println(i);
		    	if(f==0){
		    		f=1;
		    		min = a[i];

		    		i = f1(a,i);
		    		sum+=min;
		    	}else{
		    		f = 0;
		    		max = a[i];
		    		i = f2(a,i);
		    		sum+=max;
		    	}
		    }
		    System.out.println(sum);

		}
	}
}
