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());
        //String s[]=br.readLine().split(" ");
        while(t-->0){
            int n=Integer.parseInt(br.readLine());
            String s[]=br.readLine().split(" ");
            long arr[]=new long[n];
            for(int i=0;i<n;i++){
                arr[i]=Long.parseLong(s[i]);
            }
            long prev=arr[0];
            long max=prev;
            long sum=0;
            for(int i=1;i<n;i++){
                if(arr[i]*prev<0){
                    sum+=max;
                    max=arr[i];
                }
                else{
                    max=Math.max(max,arr[i]);
                }
                prev=arr[i];
            }
            sum+=max;
            bw.write(sum+"\n");
        }
        bw.flush();
    }
}