import java.util.PriorityQueue;
import java.util.Scanner;

public class Alternating_Subsequence {
    public static void helper(int[] nums) {
        int neg = 0;
        int pos = 0;
        int n = nums.length;

        boolean f = false;
        int i = 0;
        while (i < n && nums[i] > 0) i++;
        if (i < n) {
            neg++;
            i++;
            for (; i < n; i++) {
                if (nums[i] < 0 && !f) continue;
                else if (nums[i] < 0 && f) {
                    neg++;
                    f = false;
                } else if (nums[i] > 0 && f) continue;
                else {
                    neg++;
                    f = true;
                }
            }
        }

        f = true;
        i = 0;
        while (i < n && nums[i] < 0) i++;
        if (i < n) {
            pos++;
            i++;
            for (; i < n; i++) {
                if (nums[i] < 0 && !f) continue;
                else if (nums[i] < 0 && f) {
                    pos++;
                    f = false;
                } else if (nums[i] > 0 && f) continue;
                else {
                    pos++;
                    f = true;
                }
            }
        }
//        System.out.println(pos);
//        System.out.println(neg);
        int res = 0;
        int max = Integer.MIN_VALUE;
        if (pos >= neg) {
            f = true;
            int idx = 0;
            while (idx < n && nums[idx] < 0) idx++;
            max = nums[idx];
            for (; idx < n; idx++) {
                if (nums[idx] < 0 && !f) max = Math.max(max, nums[idx]);
                else if (nums[idx] < 0 && f) {
                    res += max;
                    max = nums[idx];
                    f = false;
                }
                else if (nums[idx] > 0 && f) max = Math.max(max, nums[idx]);
                else {
                    res += max;
                    max = nums[idx];
                    f = true;
                }
            }
            res += max;
        }
        else {
            f = false;
            int idx = 0;
            while (idx < n && nums[idx] > 0) idx++;
            max = nums[idx];
            for (; idx < n; idx++) {
                if (nums[idx] < 0 && !f) max = Math.max(max, nums[idx]);
                else if (nums[idx] < 0 && f) {
                    res += max;
                    max = nums[idx];
                    f = false;
                }
                else if (nums[idx] > 0 && f) max = Math.max(max, nums[idx]);
                else {
                    res += max;
                    max = nums[idx];
                    f = true;
                }
            }
            res += max;
        }
        System.out.println(res);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) nums[i] = sc.nextInt();
            helper(nums);
        }
    }
}
