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

public class MainClass {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        int numTestCases = Integer.parseInt(in.readLine());

        for (int i=0; i<numTestCases;i++) {
            long[] nums = new long[Integer.parseInt(in.readLine())];

            String[] s = in.readLine().split(" ");

            for (int j=0; j<s.length; j++)  {
                nums[j] = Integer.parseInt(s[j]);
            }

            long ret = maxAlternateSubsequence(nums);
            System.out.println(ret);

        }
    }

    public static long maxAlternateSubsequence(long[] nums) {

        if (nums.length == 0) {
            return 0;
        }

        boolean isPositive = nums[0] > 0;
        return maxAlternateSubsequenceRecursive(nums, 0, isPositive);
    }

    private static long maxAlternateSubsequenceRecursive(long[] nums, int index, boolean isPositive) {

        if (index == nums.length) {
            return 0;
        }

        long currSum = Long.MIN_VALUE;

        if (isPositive) {
            while (index < nums.length && nums[index] > 0) {
                currSum = Math.max(currSum, nums[index]);
                index++;
            }
        } else {
            while (index < nums.length && nums[index] < 0) {
                currSum = Math.max(currSum, nums[index]);
                index++;
            }
        }

        return currSum + maxAlternateSubsequenceRecursive(nums, index, !isPositive);
    }

}