import java.util.*;
public class Solution{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        StringBuffer sb = new StringBuffer();
        while(t-->0){
            int n = sc.nextInt();
            int[]arr = new int[n];
            for(int i = 0;i<n;i++) arr[i]=sc.nextInt();
            int max = arr[0];
            long sum = 0;
            for(int i = 1;i<n;i++){
                if((arr[i]*arr[i-1])<0){
                    sum+=max;
                    max = Integer.MIN_VALUE;
                }
                if(arr[i]>max) max = arr[i];
            }
            sum+=max;
            sb.append(sum+"\n");
        }
        System.out.println(sb);
    }
}