

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner inp = new Scanner(System.in);

		int num_test = inp.nextInt();
		
		for(int t = 0;t<num_test;t++) {
			
			
			int n = inp.nextInt();
			int[] a = new int[n];
		
			
			for(int i = 0;i<n;i++)
			{
				a[i] = inp.nextInt();
				
			}
			
			int index = 0;
			if(a[0] > 0)
			{
				index = 1;
				
			}
			else
			{
				index = 2;
			}
			int max_ele = a[0];
			long sum = 0;
			for(int i = 0;i<n;i++)
			{
				
				
				if((a[i] > 0) && (index == 1) )
				{
					max_ele = Math.max(max_ele,a[i]);
					index = 1;
				}
				else if((a[i] < 0) && (index == 2))
				{
					max_ele = Math.max(max_ele,a[i]);
					index = 2;
				}
				
				else
				{	
					sum  = sum + max_ele;
					if(a[i] > 0)
					{
						index = 1;
					}
					else
					{
						index = 2;
					}
					max_ele = a[i];
					
					
				}
				
			}
			
			sum = sum + max_ele;
			
		
		}

}
}