import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int totalCases = Integer.parseInt(br.readLine());

        while(totalCases-->0)
        {
            int n = Integer.parseInt(br.readLine());
            String[] str = br.readLine().split(" ");

            int[] a = new int[n];
            for(int i=0; i<n; i++) a[i] = Integer.parseInt(str[i]);

            System.out.println(Math.max(getResult(n, a, true), getResult(n, a, false)));
        }
    }

    public static long getResult(int n, int[] a, boolean initial)
    {
        boolean lookingForPositive = initial;

        int index = 0;

        int[] dp = new int[n];
        Arrays.fill(dp, 1);

        if(lookingForPositive)
        {
            while (index < n && a[index] < 0)
            {
                dp[index] = 0;
                index++;
            }
        }

        if(!lookingForPositive)
        {
            while (index < n && a[index] > 0)
            {
                dp[index] = 0;
                index++;
            }
        }

        long result = 0;
        if(index > 0) result = a[index - 1];

        for(int i=index; i<n; i++)
        {
            if(lookingForPositive && a[i] < 0)
            {
                dp[i] = dp[i-1];
                continue;
            }
            else if(!lookingForPositive && a[i] > 0)
            {
                dp[i] = dp[i-1];
                continue;
            }

            for(int j=0; j<i; j++)
            {
                if(lookingForPositive)
                {
                    if(a[j] < 0) dp[i] = Math.max(dp[i], dp[j] + 1);
                }
                else
                {
                    if(a[j] > 0) dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }

            result += a[i];

            lookingForPositive = !lookingForPositive;
        }

        return result;
    }
}