// "static void main" must be defined in a public class.
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int test_case = Integer.parseInt(br.readLine());
        while(test_case--!=0){
            int n = Integer.parseInt(br.readLine());
            int arr[] = new int[n];
            String string[] = br.readLine().split(" ");
            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(string[i]);
            }
            long sum = 0;
            int i=0;
            while(i<n){
                int max = Integer.MIN_VALUE;
                while(i<n && arr[i]<0){
                    max = Math.max(max, arr[i]);
                    i++;
                }
                if(max!=Integer.MIN_VALUE){
                    sum+=max;        
                }
                max = Integer.MIN_VALUE;
                while(i<n && arr[i]>0){
                    max = Math.max(max, arr[i]);
                    i++;
                }
                if(max!=Integer.MIN_VALUE){
                    sum+=max;        
                }
            }
            System.out.println(sum);
        }
    }
}