import java.util.ArrayList;
import java.util.Scanner;

public class Train {
    public static void main(String[] args) {
        new Train();
    }

    private Train() {
        Scanner kb = new Scanner(System.in);
        int t =kb.nextInt();

        for(int i=0;i<t;i++){
            long res=0;
            long min=Long.MIN_VALUE;
            long max=Long.MIN_VALUE;
            long n = kb.nextLong();
            for(long j=0;j<n;j++){
                long a =kb.nextLong();
                if(a<0){
                    if(max!=Long.MIN_VALUE){
                        res+=max;
                        max=Long.MIN_VALUE;
                    }
                    min=Long.max(min,a);
                }
                if(a>0){
                    if(min!=Long.MIN_VALUE){
                        res+=min;
                        min=Long.MIN_VALUE;
                    }
                    max = Long.max(max,a);
                }
        }
            if(min!=Long.MIN_VALUE){
                res+=min;
            }
            if(max!=Long.MIN_VALUE){
                res+=max;
            }
            System.out.println(res);
    }
}}