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

public class sample{

public static void main(String args[]) throws IOException{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();

int a[]=new int[n];

for(int i=0;i<n;i++){
    a[i]=sc.nextInt();
}


boolean flag=false;
long ans=0;
int max1=Integer.MIN_VALUE,max2=Integer.MIN_VALUE;
for(int i=1;i<n;i++){
    
    if(a[i]<0&&max1<a[i]){
        max1=a[i];
        
        if(a[i-1]>0){
            if(max2!=Integer.MIN_VALUE)
            ans+=max2;
            else
            ans+=a[i-1];
        
            max2=Integer.MIN_VALUE;
        }
        
    }
    
    if(a[i]>0&&max2<a[i]){
        max2=a[i];
        if(a[i-1]<0){
            if(max1!=Integer.MIN_VALUE)
            ans+=max1;
            else
            ans+=a[i-1];
    
            max1=Integer.MIN_VALUE;
            
        }
        
    }
}

if(a[a.length-1]>0){
    if(max2!=Integer.MIN_VALUE)
    ans+=max2;
    else
    ans+=a[a.length-1];
    
}
else{
    
if(max1!=Integer.MIN_VALUE)
ans+=max1;
else
ans+=a[a.length-1];
    
}
    
    


System.out.println(ans);


}

}
}


