import java.util.Scanner;
public class Alternatingsubsequence {

	public static void main(String[] args) {
		Scanner obj=new Scanner(System.in);
		int t=obj.nextInt();
		while(t-->0)
		{
			int n=obj.nextInt();
			int max=0,max2=0;
			long sum=0;
			int[] arr=new int[n];
			for(int i=0;i<n;i++)
			{
				 arr[i]= obj.nextInt();
					
			}
			for(int i=0;i<n;i++)
			{
				if(max==0&&arr[i]>0)
				{
					max=arr[i];
				}
					
				if(arr[i]>max&&arr[i]>0)
				{
					max=arr[i];
				}
				else if(arr[i]<0&&max!=0)
				{
					sum+=max;
					max=0;
				}
				if(max2==0&&arr[i]<0)
				{
					max2=arr[i];
				}
				if(max2<arr[i]&&arr[i]<0)
				{
					max2=arr[i];
				}
				else if(arr[i]>0&&max2!=0)
				{
					sum+=max2;
					max2=0;
					
				}
					
			}
			if(max==0)
				sum+=max2;
			else if(max2==0)
				sum+=max;
			System.out.println(sum);
			//System.out.println(max2);
		}

	}

}
