import java.util.Scanner;
import java.io.*;
import java.lang.*;
public class Solution
{
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long t=sc.nextLong();
        while(t-->0)
        {
            int n=sc.nextInt();
            long[] a= new long[n];
            for(int i=0;i<n;i++)
            {
                a[i]=sc.nextLong();
            }
            long sum=0;
            long max=a[0];
            for(int i=0;i<n;i++)
            {
                if(max*a[i]<0)
                {
                    sum+=max;
                    max=a[i];
                }
                else
                {
                    if(max<a[i])
                    max=a[i];
                }
            }
            sum+=max;
            System.out.println(sum);
        }
    }
}