import java.util.*;
public class SubSeqSumBySize {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            int[] a = new int[n+1];
            for(int i=1;i<=n;i++){
                a[i] = sc.nextInt();
            }
            System.out.println(maxSumBySize(a,n));
        }
        sc.close();
    }

    private static long maxSumBySize(int[] a, int n) {
        long[] sum = new long[n+1];
        sum[0] = a[0];int lastPos = 0, lastNeg = 0;
        sum[1] = a[1];
        if(a[1] > 0) lastPos = 1;
        else lastNeg = 1;
        for(int i=2;i<=n;i++){
            if(a[i] * a[i-1] < 0){
                int x = (a[i] > 0) ? lastNeg: lastPos;
                sum[i] = sum[x] + a[i];
                if(a[i] > 0)
                    lastPos = i;
                else lastNeg = i;
            }
            else if(a[i] > 0){
                sum[i] = sum[lastNeg] + a[i];
                if(sum[i] > sum[lastPos]) 
                    lastPos = i;
            }
            else{
                sum[i] = sum[lastPos] + a[i];
                if(sum[i] > sum[lastNeg]) 
                    lastNeg = i;
            }
        }
        int x = Math.max(lastNeg, lastPos);
        return sum[x];
    }
}