import java.util.*;
 
public class Solution
{
    public static void main(String[] args)
    {
        Scanner scn = new Scanner(System.in);
        
        int t = scn.nextInt();
        
        while(t>0)
        {
            int n = scn.nextInt();
            int[] arr = new int[n];
            for(int i=0; i<n; i++) arr[i] = scn.nextInt();
            
            int sum = 0;
            int prevval = -1;
            for(int i=0; i<n; i++)
            {
                int val = arr[i];
                
                if(i==0)
                {
                    sum = sum + val;
                    prevval = val;
                }
                else
                {
                    if(val > 0 && prevval > 0)
                    {
                        if(val > prevval)
                        {
                            sum = sum - prevval + val;
                            prevval = val;
                        }
                    }
                    else if(val < 0 && prevval < 0)
                    {
                        if(val > prevval)
                        { 
                            sum = sum - prevval + val;
                            prevval = val;
                        }
                    }
                    else
                    {
                        sum = sum + val;
                        prevval = val;
                    }
                }
            }
            
            
            System.out.println(sum);
            t--;
        }
        
    }
    
}