import java.util.Scanner;

public class C1343 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0) {
            int sign = 0;
            int maxP = Integer.MIN_VALUE;
            int maxN = Integer.MIN_VALUE;
            long sum = 0;
            int n = sc.nextInt();
            for(int i = 0; i < n-1; i++){
                int temp = sc.nextInt();
                if(temp < 0){
                    if(i != 0 && sign==1){
                        sum += maxP;
                        maxP = Integer.MIN_VALUE;
                    }
                    sign = -1;
                    if(maxN<temp) maxN = temp;
                }else{
                    if(i != 0 && sign==-1){
                        sum += maxN;
                        maxN = Integer.MIN_VALUE;
                    }
                    sign = 1;
                    if(maxP<temp) maxP= temp;
                }
//                System.out.print(sum + " ");
            }
            int temp = sc.nextInt();
            if(temp<0){
                if(sign!=-1){
                    sum+=maxP;
                    sum+=temp;
                }else{
                    sum+= Math.max(maxN,temp);
                }
            }else{
                if(sign!=1){
                    sum+=maxN;
                    sum+=temp;
                }else{
                    sum+= Math.max(maxP,temp);
                }
            }
            System.out.println(sum);
        }
    }
}