

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

public class Solution
 {
  public static void main(String[] args) 
	{
    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    for(int i=0;i<t;i++){
    	int n = in.nextInt();
    	int[] arr = new int[n+1];
    	for(int j=0;j<n;j++){
    		arr[j]=in.nextInt();
    	}
    	arr[n]=0;
    	int max =1;
    	int min = -1000000000;
    	long sum=0;
    	for(int j =0;j<n;j++){
    		if(arr[j]>0){
    			max =Math.max(arr[j],max);
    			if(arr[j+1]<=0){
    				sum+=max;
    				max=1;
    			}
    		}else{
    			min = Math.max(arr[j],min);
    			if(arr[j+1]>=0){
    				sum+=min;
    				min=-1000000000;
    			}
    		}
    	}
    	System.out.println(sum);
    }
  }
}