// Java program to find longest alternating 
// subarray starting from every index. 
import java.util.*; 

public class Longest{ 
	
	public static void longestAlternating(int a[], 
											int n) 
	{ 
		long[] count = new long[n]; 
		int start=a[0];

		// Fill count[] from end. 
		count[0] = a[0];
	    int l=1;
	    
		for (int i = 1; i<n; i++) { 
			if (a[i] * a[i-1] < 0) 
				{count[i] = count[i - 1] + a[i]; l++;}
			else
			{	
			    if(l==1)
			    count[i] = (int)Math.max(count[i-1],a[i]); 
			    else
			    {
			        count[i]=count[i-1];
			    }
		//	a=count[i];
			    
			}
		} 
		
	

		
		
	System.out.println(count[n-1]);
		
	} 
	
	// driver program 
	public static void main(String[] args) 
	{ 
		
		
		

		Scanner in = new Scanner(System.in);
		int t=in.nextInt();
		//in.nextLine();
		
		while(t>0)
		{
		    
		       
		      int n=in.nextInt();
		      int[] a = new int[n];
		      
		      for(int i=0;i<n;i++)
		      {
		          a[i]=in.nextInt();
		      }
	          
	          longestAlternating(a,n);
	
                
		    t--;
		}
	} 
} 

// This code is contributed by rishabh_jain 
