import java.util.Arrays;
import java.util.Scanner;
public class candies
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in); 
		int t,i;
		t=sc.nextInt();
		while(t>0)
		{
			t--;
			int n=sc.nextInt();
			long a[]=new long[n];
			
			for(i=0;i<n;i++)
			{
				a[i]=sc.nextLong();
				
			}
			long sum=0;
			int l=0;
			sum+=a[0];
			long max=a[0];
			for(i=1;i<n;i++)
			{
				if(a[i]*a[i-1]<0)
				{
					sum+=a[i];
					max=a[i];
				}
				else
				{
					if(a[i]>max)
					{
						sum-=max;
						max=a[i];
						sum+=a[i];
					}
				}
			}
			System.out.println(sum);
		}
	}
}