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

public class Solution {
    public static void main(String[] args) throws IOException{
        try{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        while(t-->0){
            int n=Integer.parseInt(br.readLine());
            String[] str1=br.readLine().split(" ");
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=Integer.parseInt(str1[i]);
            }
            long incl=a[0];
            long sum=0;
            long max=incl;
           for(int i=1;i<n;i++){
               if(a[i]*incl<0){
                   max=a[i];
                   sum+=max;
               }
                
                else{
                    max=Math.max(max,a[i]);
                }
               incl=a[i];
            }
            sum+=max;
            System.out.println(sum);
        }
        }catch(Exception e){}
    }
}
