import java.nio.file.LinkOption;
import java.util.Scanner;

public class codefcf {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);


        int t = s.nextInt();
        while (t-- > 0) {
            int n = s.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = s.nextLong();
            }

            long sumTillnow = 0;
            long minN = Long.MIN_VALUE;
            long maxp = Long.MIN_VALUE;

            int pcheck = 0;
            int ncheck = 0;
            for (int i = 0; i < a.length; i++) {
                if(a[i]>0){
                    if(a[i]>maxp){
                        sumTillnow -= maxp;
                        maxp = a[i];
                        sumTillnow += maxp;
                    }
                    minN = Long.MIN_VALUE;
                    pcheck = 1;
                }
                else{
                    if(a[i]>minN){
                        sumTillnow -= minN;
                        minN = a[i];
                        sumTillnow += minN;
                    }
                    maxp = Long.MIN_VALUE;
                    ncheck = 1;
                }
            }
            if(pcheck==0||ncheck==0){
                System.out.println(-1);
            }
            else{
                System.out.println(sumTillnow);
            }

        }
    }
}

