import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner s=new Scanner(System.in);
	    int t=s.nextInt();
	    while(t-->0)
	    {
	        int n=s.nextInt();
	        int arr[]=new int[n];
	        for(int i=0;i<n;i++)
	        {
	            arr[i]=s.nextInt();
	        }
	        int sum=0;
	        for(int i=0;i<n;i++)
	        {
	            int cur=arr[i];
	            int j=i;
	            while(j<n && sign(arr[i])==sign(arr[j]))
	            {
	                cur=Math.max(cur,arr[j]);
	                j++;
	            }
	            i=j-1;
	            sum+=cur;
	        }
	        System.out.println(sum);
	    }
	    
	}
	public static boolean sign(int num)
	{
	    return num>0;
	}
}
