import java.util.*;
public class sequence{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0){
			int n = sc.nextInt();
			int max = Integer.MIN_VALUE;
			long sum =0;
			int max1 = Integer.MIN_VALUE;
			int flag1=0;
			int flag2=0;
			for(int i=0;i<n;i++){
				int x = sc.nextInt();
				if(x>0 && x>max){
					max=x;
					flag1=1;
					if(flag2==1){
						sum=sum+max1;
						max1 = Integer.MIN_VALUE;
						flag2=0;
					}

				}
				else if(x<0 && x>max1){
					flag2=1;
					if(flag1==1){
						sum=sum+max;
						flag1 =0;
						max = Integer.MIN_VALUE;	
					}
					max1 = x;
				}
			}
			//System.out.println("before"+sum);
			if(max1!=Integer.MIN_VALUE){
				//System.out.println("anuj");
				sum=sum+max1;
			}
			else if(max!=Integer.MIN_VALUE){
				//System.out.println("anujv");
				sum=sum+max;
			}
			//System.out.println(max);
			//System.out.println(max1);
			System.out.println(sum);
		}
	}
}