

import java.util.*;

public class hash {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n=sc.nextInt();
			int ar[]=new int[n];
			for(int i=0;i<n;i++)
			{
				ar[i]=sc.nextInt();
			}
			int s=1;
			int last=0;
			int size=0;
			long sum=0;
			
			for(int i=0;i<n;i++)
			{
				
				if(s==1&&ar[i]>0)
				{
					size++;
					last=ar[i];
					s=-1;
					sum=sum+ar[i];
				}
				else if(s==-1&&ar[i]>0&&ar[i]>last)
				{
					sum=sum-last+ar[i];
					last=ar[i];
				}
				else if(s==-1&&ar[i]<0)
				{
					s=1;
					sum=sum+ar[i];
					last=ar[i];
					size++;
				}
				else if(s==1&&ar[i]<0&&ar[i]<last)
				{
					last=ar[i];
					sum=sum-last+ar[i];
				}
				//System.out.println(sum+" sa");
			}
			s=-1;
			int size1=0;
			int sum1=0;
		        last=0;
			for(int i=0;i<n;i++)
			{
				
				if(s==1&&ar[i]>0)
				{
					size1++;
					last=ar[i];
					s=-1;
					sum1=sum1+ar[i];
				}
				else if(s==-1&&ar[i]>0&&ar[i]>last)
				{
					sum1=sum1-last+ar[i];
					last=ar[i];
				}
				else if(s==-1&&ar[i]<0)
				{
					s=1;
					sum1=sum1+ar[i];
					last=ar[i];
					size1++;
				}
				else if(s==1&&ar[i]<0&&ar[i]<last)
				{
					last=ar[i];
					sum1=sum1-last+ar[i];
				}
			}
			//System.out.println(sum1+" "+size1);
			if(size1>size)
			{
				System.out.println(sum1);
			}
			else if(size1<size)
			{
				System.out.println(sum);
			}
			else
			{
				if(sum1>sum)
					System.out.println(sum1);
				else
					System.out.println(sum);
				
			}
			
			
			

		}
	}

}
