
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Demo01 {
	
	
	public static void main(String [] args)
	{
		
		Scanner in = new Scanner(System.in);
		
		int t= in.nextInt();
		
		for(int j =0;j<t;j++)
		{
			int n = in.nextInt();
			
			long [] a =new long [n];
			
			long  maxSum = Long.MIN_VALUE;
			int maxLen =0;
			
			for(int i =0;i<n;i++)
			{
				a[i]  = in.nextLong();
				
			}
			
			int tempLen =0;
			long tempSum =0;
			
			for(int  i =0;i<n;i++)
			{
				if(i<n-1)
				{
				if(a[i]*a[i+1]<0)
				{
					tempLen++;
					tempSum  =tempSum+a[i];
				}
				else {
					
					tempLen++;
					tempSum =tempSum+a[i];
					if(tempLen>=maxLen)
					{
						maxLen = tempLen;
						if(maxSum<tempSum)
						{
							maxSum = tempSum;
						}
						
					}
					tempLen =0;
					tempSum = 0;
					
				}
				
				}
				
				else {
					
					if(n==1)
					{
					maxSum =a[0];

					}
					else {
					
					if(a[i-1]*a[i]<0)
					{
						tempSum =tempSum+a[i];
						tempLen++;
					}
					else {
					tempSum =tempSum+a[i];
					tempLen++;
					}
					
					if(tempLen>=maxLen)
					{
						maxLen = tempLen;
						if(maxSum<tempSum)
						{
							maxSum = tempSum;
						}
						
					}
				}
				}
				
			}
			
			System.out.println(maxSum);
			
			
			
			
		}
		
		
		
	}
	
	
}