import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for(int test = 0; test<t; test++){
            int n = in.nextInt();
            int[] arr = new int[n];
            for(int i = 0; i<n; i++){
                arr[i] = in.nextInt();
            }
            boolean pos = arr[0] > 0;
            Stack<Integer> stack = new Stack<>();
            stack.push(arr[0]);
            for(int i=1; i<n; i++){
                if(arr[i] < 0 == stack.peek() < 0  && arr[i] > stack.peek()){
                    stack.pop();
                    stack.push(arr[i]);
                } else if(arr[i] < 0 != stack.peek() < 0){
                    stack.push(arr[i]);
                }
            }

            long sum = 0;
            for (Integer i: stack){
                sum+=i;
            }
            System.out.println(sum);
        }
    }
}
