import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        for(int tt=0;tt<t;tt++)
        {
            int n = s.nextInt();
            long[] a = new long[n];
            for(int i=0;i<n;i++)
            a[i] = s.nextLong();
            int maxNegativeIndex = -1;
            int maxPositiveIndex = -1;
            int[] dp = new int[n];
            dp[n-1] = 1;
            long[] sum = new long[n];
            sum[n-1] = (long)a[n-1];
            if(a[n-1]>0L)
            maxPositiveIndex = n-1;
            else
            maxNegativeIndex = n-1;
            int max = 1;
            for(int i=n-2;i>=0;i--)
            {
                if(a[i]>0)
                {
                    if(maxNegativeIndex!=-1)
                    {
                        dp[i] = dp[maxNegativeIndex] + 1;
                        sum[i] = sum[maxNegativeIndex] + (long)a[i];
                    } else{
                        dp[i] = 1;
                        sum[i] = (long)a[i];
                    }
                    if(maxPositiveIndex==-1)
                    {
                        maxPositiveIndex = i;
                        continue;
                    }
                    if(dp[i]>dp[maxPositiveIndex])
                    {
                        maxPositiveIndex = i;
                    } else if(dp[i]==dp[maxPositiveIndex]){
                        if( sum[i]>sum[maxPositiveIndex]  )
                        {
                            maxPositiveIndex = i;
                        }
                    }
                } else {
                    if(maxPositiveIndex!=-1){
                        dp[i] = dp[maxPositiveIndex] + 1;
                         sum[i] = sum[maxPositiveIndex] + (long)a[i];
                    } else{
                        dp[i] = 1;
                        sum[i] = (long)a[i];
                    }
                    if(maxNegativeIndex==-1)
                    {
                        maxNegativeIndex = i;
                        continue;
                    }
                    if(dp[i]>dp[maxNegativeIndex])
                    {
                        maxNegativeIndex = i;
                    } else if(dp[i]==dp[maxNegativeIndex])
                    {
                        if( sum[i]>sum[maxNegativeIndex]  )
                        {
                            maxNegativeIndex = i;
                        }
                    }
                }
                max = Math.max(dp[i],max);
            }
            // for(int i=0;i<n;i++)
            // {
            //     System.out.print(dp[i]+" ");
            // }
            // System.out.println();
            // for(int i=0;i<n;i++)
            // {
            //     System.out.print(sum[i]+" ");
            // }
            long ans = Long.MIN_VALUE;
            for(int i=0;i<n;i++)
            {
                if(dp[i]==max)
                ans = Math.max(ans,sum[i]);
            }
            System.out.println(ans);
        }
    }
}