import java.util.*;
import java.io.*;
public class alternatingsubsequence {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = sc.nextInt();
        for(int i = 0; i < t; i++){
            ArrayList<Integer>listOfNums = new ArrayList<>();
            int n = sc.nextInt();
            long sum = 0;
            for(int j = 0; j < n; j++){
                listOfNums.add(sc.nextInt());
            }
            long start = listOfNums.get(0);
            long max = start;
            boolean isPositive;
            if(start>0){
                isPositive = true;
            }
            else{
                isPositive = false;
            }
            for(int j = 1; j < n; j++){
                int f = listOfNums.get(j);
                if((isPositive && f>0) || (!isPositive && f<0)){
                    if(f > max){
                        max = f;
                    }
                }
                else{
                    isPositive = !isPositive;
                    sum+=max;
                    max = f;
                }
            }
            out.println(sum+max);
        }
        out.close();
    }
}
