import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args)throws IOException {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        int T=Integer.parseInt(br.readLine());
        while(T-->0){
            int n=Integer.parseInt(br.readLine());
            String[] str=br.readLine().split(" ");
            int[] arr=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=Integer.parseInt(str[i]);
            }
            boolean flag=true;
            if(arr[0]<0)
                flag=false;
            else
                flag=true;
            int max=arr[0],min=arr[0];
            long sum=0;
            for(int i=1;i<n;i++){
                if(arr[i]*arr[i-1]<0){
                    
                    if(flag){
                        sum+=max;
                        //max=arr[i];
                    }
                    else{
                        sum+=min;
                        //min=arr[i];
                    }
                    max=min=arr[i];
                    //System.out.print(sum+" ");
                    flag=!flag;
                }
                if(flag){
                    max=Math.max(max,arr[i]);
                }
                if(!flag){
                    min=Math.max(min,arr[i]);
                }
            }
            //System.out.println();
            if(flag)
                sum+=max;
            else
                sum+=min;
            bw.write(sum+"\n");
        }
        bw.flush();
    }
}