import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            int arr[] = new int[n];
            for(int i=0;i<n;i++){
                arr[i] = sc.nextInt();
            }

            int res = GFG(arr,n);
            System.out.println(res);
        }
    }

    public static boolean sign(int a){
        return a>0;
    }

    public static int GFG(int arr[],int n){
        int ans= 0;
        int i =0;
        while(i<n){
            int j=i;
            int maxa = Integer.MIN_VALUE;
            while(j<n && sign(arr[i])==sign(arr[j])){
                maxa = Math.max(maxa,arr[j]);
                j++;
            }
            ans = ans+maxa;
            i = j;
        }

        return ans;
    }
}